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 2005 Forums
 Transact-SQL (2005)
 Cannot figure out this tricky sql

Author  Topic 

gamaz
Posting Yak Master

104 Posts

Posted - 2010-05-04 : 14:47:32
Hi,
I have the following code in sql




DECLARE

@slsman NVARCHAR(8)
, @cust_name NVARCHAR(60)
, @customer_rowpointer UNIQUEIDENTIFIER


SELECT @slsman = null, @cust_name = null, @customer_rowpointer = null
SELECT TOP 1 @slsman = customer.slsman
,@customer_rowpointer = customer.rowpointer
from customer

Now I need to change the above code such that if slsman field is blank in customer then it should look for the field from a differnt table in the database named sales and table saleman_detail.

I have to incorporate this logic in the above code. I am not sure how to do this. I appreciate any help.
Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 14:49:32
IF @slsman = ''
SELECT @slsman=yourrequiredfield
FROM sales..saleman_detail

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gamaz
Posting Yak Master

104 Posts

Posted - 2010-05-05 : 09:46:14
Thanks vishkh for your help. I appreciate it.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-05 : 14:46:15
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -