0

So I was wondering how I can do this, I am using SQL Server Compact and need to do a specific thing.

I need to append a string to an int, resulting in a string if a column is not equal to a value

For example lets say I have this query here

SELECT id, Auto FROM example

Right now to get what I want I will have to do this select and then resolve it after like so

string id = dr["id"].ToString() + 
                dr["Auto"].ToString().IsNotNullOrWhitespace() 
                    ? " (Auto)" : "");

How can I get the same result in SQL? AS something like this

SELECT id ..... as id FROM example

(Auto is defined asINT NULL)

1 Answer 1

1

Not tested but you can try the following

SELECT (
        case id
             WHEN 1 
                  THEN id + ' (Auto)' 
             ELSE id END) as id 
FROM example
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.