May 16, 2012 at 4:14 am
iam using if in SP
if (@lused = '')
begin
@lused = 0
@balleave = Convert.ToInt32(@lused)
end
slq statement s follows
but i get error incorrect syntax near @lused = 0
May 16, 2012 at 4:18 am
Use SET.
John
May 16, 2012 at 4:41 am
ssurekha2000 (5/16/2012)
iam using if in SPif (@lused = '')
begin
@lused = 0
@balleave = Convert.ToInt32(@lused)
end
slq statement s follows
but i get error incorrect syntax near @lused = 0
As John said above you need to use SET to assign values to variables. Other than that you need to use CAST or CONVERT functions of SQL Server for type casting.
It should be some thing like this:
IF (@lused = '')
BEGIN
SET @lused = '0'
SET @balleave = CAST(@lused AS INT)
END
May 16, 2012 at 5:04 am
Thanks
May 16, 2012 at 6:55 pm
Divine Flame (5/16/2012)
IF (@lused = '')
BEGIN
SET @lused = '0'
SET @balleave = CAST(@lused AS INT)
END
Or you can do this:
IF (@lused = '') SELECT @lused = '0', @balleave = 0
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply