show user defined value not actually in table | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

show user defined value not actually in table


the foloowing table is emp table name salary X 10000 Y 20000 Z 2000 SELECT ‘The SAL is VERY LESS’ + CAST(SAL AS varchar(12)) as salary
FROM EMP
WHERE SAL <5000
GO RESULT: salary The SAL is VERY LESS2000 BUT I WANT TO SHOW ONLY ‘The SAL is VERY LESS’ INSTEAD OF ‘The SAL is VERY LESS2000’
You only want to show the comment, not the SAL value. Then why does SAL appear in your column list? SELECT ‘The SAL is VERY LESS’
FROM EMP
WHERE SAL <5000 Consider posting to the "New SQL Server User" section –http://www.sql-server-performance.com/forum/default.asp?CAT_ID=13
the statement will create a new column.
But I don’t want any new column be created.
I want to show the original column as it is.

You seem to be confused about the very basics of T-SQL. SELECT does not create any columns. You are just selecting data from a table, and returning a string for each row where SAL<5000. Please educate yourself on the basics, before posting questions.
sorry ..Actually I have written in wrong way.
I should say that ur sql statement showing new column name. But I don’t want to show any new column.I want to show the
different attribute value from original value
quote:Originally posted by Adriaan You seem to be confused about the very basics of T-SQL. SELECT does not create any columns. You are just selecting data from a table, and returning a string for each row where SAL<5000. Please educate yourself on the basics, before posting questions.

Then add an alias for the expression: SELECT ‘The SAL is VERY LESS’ AS Salary
FROM EMP
WHERE SAL <5000 Note that you’ll get the same line for each row in EMP where SAL<5000.
I think I m not clear to u.
let me clear. supoose in the following emp table . name sal
x 60,000
y 10,000 here sal as varchar(12).
I want result like this name sal
x 60,000
y very less salary don’t want to show any new extra column
quote:Originally posted by Adriaan Then add an alias for the expression: SELECT ‘The SAL is VERY LESS’ AS Salary
FROM EMP
WHERE SAL <5000 Note that you’ll get the same line for each row in EMP where SAL<5000.

Then use CASE, which can evaluate the salary: SELECT name, CASE WHEN SAL<5000 ‘Very less salary’ ELSE CAST(SAL AS VARCHAR(100)) END AS Salary
FROM EMP If you put the comparison in the WHERE clause, then you see only rows where SAL<5000.
showing the following error msg: Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ‘Very less salary’.
quote:Originally posted by Adriaan Then use CASE, which can evaluate the salary: SELECT name, CASE WHEN SAL<5000 ‘Very less salary’ ELSE CAST(SAL AS VARCHAR(100)) END AS Salary
FROM EMP If you put the comparison in the WHERE clause, then you see only rows where SAL<5000.

Read BOL for CASE …<br /><br />My query was missing the THEN keyword – mistakes happen.[<img src=’/community/emoticons/emotion-2.gif’ alt=’:D‘ />]
Thanks a lot for your help..really appreciate yor guidance.<br /><br />thanks once again.<br /><br />regds,<br />litu deb<br /><br /><blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Adriaan</i><br /><br />Read BOL for CASE …<br /><br />My query was missing the THEN keyword – mistakes happen.[<img src=’/community/emoticons/emotion-2.gif’ alt=’:D‘ />]<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
]]>