February 26, 2014 at 3:03 pm
I have a stored procedure, I need to set the parameter default value to below, but
in it shows the syntax error in char(9), and char(13), and char(10),
it expects select or "("
@tab varchar(1) = char(9),
@cr varchar(2) = char(13)+char(10),
anything wrong with this ?
Thanks
February 26, 2014 at 5:31 pm
I believe that default values must be literal constants and cannot include built-in functions.
This fails also:
CREATE PROCEDURE dbo.Test
(
@dt DATETIME = GETDATE()
--,@tab VARCHAR(1) = CHAR(1)
--,@cr VARCHAR(2) = CHAR(13)+CHAR(10)
)
AS BEGIN
SELECT CHAR(10)
END
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
February 26, 2014 at 5:52 pm
Don't know about the date, but this looks like it puts in the control characters correctly:
alter PROCEDURE dbo.Test
(
--@Dt DATETIME = '20140201'
,@tab VARCHAR(1) = 0x09
,@cr VARCHAR(2) = 0x1310
)
AS BEGIN
select 'dog' + @tab + @tab + @tab + 'cat' + @cr
select CAST(@tab as varbinary(1)), CAST(@cr as varbinary(2))
END
return
February 26, 2014 at 6:10 pm
David Webb-CDS (2/26/2014)
Don't know about the date, but this looks like it puts in the control characters correctly:
alter PROCEDURE dbo.Test
(
--@Dt DATETIME = '20140201'
,@tab VARCHAR(1) = 0x09
,@cr VARCHAR(2) = 0x1310
)
AS BEGIN
select 'dog' + @tab + @tab + @tab + 'cat' + @cr
select CAST(@tab as varbinary(1)), CAST(@cr as varbinary(2))
END
return
+1 David. Very clever.
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 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply