Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SP SELECT Question

Author  Topic 

WeeBubba
Starting Member

18 Posts

Posted - 2007-01-13 : 21:34:45
i want to return a datase from an SP. but i want to include my own dummy column with custom values.

i have a background in Firebird. with Firebird to achieve this I would put my logic after a FOR SELECT/DO clause so that my custom code would run before each row was committed. heres some Firebird pseudo code below. this is the best way to explain it i think. could somebody please tell me how you achieve a similar thing in sql server:

CREATE PROCEDURE ...
RETURNS(
@Id,
@Description,
@MyCustomValue
)
FOR SELECT
a.Id,
a.Description
FROM
MyTable
INTO
@Id,
@Description
DO
BEGIN
if (...conditional clause...)
@MyCustomValue = "Hello"
else
@MyCustomValue = "World"
END

so my results are like this

Id DESCription MyCustomValue
------------------------------------------------
1 edhuihe Hello
2 eddeddd World
etc

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-14 : 03:11:19
use CASE WHEN


select a.id, a.description, case when (...conditional clause...) then 'Hello' else 'World' end
from MyTable



KH

Go to Top of Page
   

- Advertisement -