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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure Help Please

Author  Topic 

DavidatHome
Starting Member

1 Post

Posted - 2002-03-28 : 17:18:17
Currently have information in a table;

Table1
-Field1
-Field2
-Field3
-Field4
-Field5
-Field6

I can produce what I want in Access but having difficulties in SQL

ACCESS QUERY

SELECT Field1, Field2, Field3, Field4, Field5, Field6, IIf((Field5 = "Yes" And Field2 = "" And Field3 = ""),"Same","") AS FieldTemp
FROM Table1

SQL QUERY

Trying to develop something in a stored procedure. Trying to do the query using T-SQL words like IF, and CASE, but can't seem to bring it all together.

Background;

Can't change the current table structure. And need to base an export to a text file on this query which needs an additional field (i.e. FieldTemp). Based on the information on Field2 and 3 and 5 as you can see the FieldTemp field value needs to change to "Same" or nothing.

Any suggestions? Thank you.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-28 : 17:23:51
SELECT Field1, Field2, Field3, Field4, Field5, Field6,
CASE WHEN Field5='Yes' AND Field2='' AND Field3=''
THEN 'Same'
ELSE ''
END AS FieldTemp
FROM Table1


Go to Top of Page
   

- Advertisement -