0

I have a @returnValue which is a varchar from a function that gets the

AnimalName varchar AnimalType varchar BigSmall int ( value is either 1 or 0 )

and just make one long string like below

@returnValue = @returnValue + AnimalName + ' ' 
+ AnimalType  + '  ' +  convert(varchar, BigSmall) + ': '

I want to replace the BigSmall if the value is 0 to 'Small' and if value is 1 to 'Big' and add it to my string @returnValue

Thanks

4
  • If this is homework you should tag it as homework. You should also do a little research, which should have yielded 2 ways to do this using either CASE ... WHEN or IF. Microsoft's SQL reference msdn.microsoft.com/en-us/library/bb510741(v=sql.105) is always a good place to start. Commented Aug 1, 2012 at 18:14
  • This is NOT homework .. I was just stuck with this in a project, yet I am new to programming .. I was going to use if else statement but I was not sure if that might actually work. Like begin if set end. Commented Aug 1, 2012 at 18:15
  • your link goes to Page not found. Commented Aug 1, 2012 at 18:18
  • That's because the closing parenthesis is part of the URL, but stackoverflow isn't recognizing that. Include the parenthesis at the end and it should work. Commented Aug 1, 2012 at 18:20

2 Answers 2

1

You will want to use a CASE statement around the BigSmall field:

@returnValue = @returnValue 
                + AnimalName + ' ' 
                + AnimalType  + '  ' 
                + CASE WHEN BigSmall = 0 THEN 'Small' ELSE 'Big' END + ': '
Sign up to request clarification or add additional context in comments.

1 Comment

You are awsome, this is resolved, but I have to wait 9 minutes to accept your response. Thanks a bunch!
1

Use this expression:

case BigSmall
  when 0 then 'Small'
  when 1 then 'Big'
  else 'Oops' end

1 Comment

Thanks this is resolved I am waiting for a timer so I can mark it as answered. Thanks a lot !

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.