Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF SET syntax in a function (SQL Server) 1

Status
Not open for further replies.

747576

Programmer
Jun 18, 2002
97
GB
Hi there,

I'm trying to set a variable in a function in SQL Server. My syntax uses:

IF @Variable1='value' SET @Variable1='new value'

this works, but when I add in AND it doesn't seem to work!
i.e.

IF @Variable1='value' AND 'Varialble2 = 'value' SET @Variable2='new value'

Have I the right syntax here, some help will be much appreciated.

Thanks

 
IF @Variable1='value' AND 'Varialble2 = 'value' SET @Variable2='new value'

should read

IF @Variable1='value' AND @Variable2 = 'value' SET @Variable2='new value'

Proof example:

declare @x int
declare @y int

SET @x=2
SET @y=1

IF @x=2 and @y=1
SET @y=0

PRINT @y


:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top