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 2008 Forums
 Transact-SQL (2008)
 Update with IF

Author  Topic 

eljapo4
Posting Yak Master

100 Posts

Posted - 2012-09-27 : 10:17:50
is this possible:

UPDATE [DR_HeatPumpCalc].[dbo].[tbl_lkupHeatPumps]
if @Filetype <> '' SET [ImageFilename] ='heatpump-' + Convert(varchar(50),@NewHeatPumpID) + @Filetype,
else SET [ImageFilename] = NULL
if @PDFFiletype <>'' [PDFDatasheetPath] = 'heatpump-' + Convert(varchar(50),@NewHeatPumpID) + @PDFFiletype
else [PDFDatasheetPath] = NULL
WHERE [HeatPumpID] = @NewHeatPumpID

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-27 : 10:21:59
it should be CASE ...WHEN


UPDATE [DR_HeatPumpCalc].[dbo].[tbl_lkupHeatPumps]
SET [ImageFilename] =CASE WHEN @Filetype <> '' THEN 'heatpump-' + Convert(varchar(50),@NewHeatPumpID) + @Filetype ELSE NULL END,
[PDFDatasheetPath] = CASE WHEN @PDFFiletype <>'' THEN 'heatpump-' + Convert(varchar(50),@NewHeatPumpID) + @PDFFiletype ELSE NULL END
WHERE [HeatPumpID] = @NewHeatPumpID


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

Go to Top of Page

eljapo4
Posting Yak Master

100 Posts

Posted - 2012-09-27 : 10:31:06
thank you this is just what I was doing after a bit of thought
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-27 : 10:33:12
welcome

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

Go to Top of Page
   

- Advertisement -