0

I have written code for stored procedure

ALTER PROCEDURE dbo.Store_Reviews_GetByProduct
    @PortalID int,
    @ProductID int

    AS
    SET NOCOUNT ON

    SELECT r.ReviewID, r.PortalID, r.ProductID, r.UserName, r.Rating, LEFT(r.Comments,200), r.Authorized, r.CreatedDate, p.ModelName
    FROM dbo.Store_Reviews r
        LEFT JOIN dbo.Store_Products p
            ON r.ProductID = p.ProductID
    WHERE r.PortalID = @PortalID
    AND r.ProductID = @ProductID
    ORDER BY r.CreatedDate DESC

In that the LEFT function is not working, instead it gives no results or select none.

I have used Substring function as well like SUBSTRING(r.comments, 0, 200) but it also gives no result.

How can I get first 200 characters of comments column??

All answers are appreciated..

5
  • 2
    SQL isn't my strong suit, but you might need to alias the result of the string function for it show up reliably in your results. Commented Aug 17, 2013 at 6:01
  • Can't reproduce - works just fine on e.g. the AdventureWorks sample DB.... Commented Aug 17, 2013 at 6:36
  • I don't think LEFT() is the issue. Does it return the entire content of comment if you remove it? Commented Aug 17, 2013 at 7:18
  • Table definition Please. Commented Aug 21, 2013 at 20:30
  • Does this also fail in Management Studio, or only in your client program? Commented Aug 21, 2013 at 20:32

1 Answer 1

1

this works fine as well

SUBSTRING(r.comments,1 ,200) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.