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)
 Set parameter = NULL if another is 0

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2009-09-02 : 14:02:12
Inserting multiple records:

DECLARE @NewInv INT		
SET @NewInv = (SELECT InvID FROM InvTable)

INSERT INTO newTable(
custid, Inv)
SELECT CustomerID, @NewInv
FROM #tempTable


Now if CustomerID is not greater than 0, @NewInv must = NULL

Just can't seem to get it working right so I stripped it down
to the basics here.

Suggestions?

Thanks,

Zath

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-02 : 14:04:12
[code]
INSERT INTO newTable(
custid, Inv)
SELECT CustomerID,CASE WHEN CustomerID >0 THEN @NewInv ELSE NULL END
FROM #tempTable
[/code]
Go to Top of Page
   

- Advertisement -