Groups | Blog | Home
all groups > sql server reporting services > november 2004 >

sql server reporting services : Substring parameter


John Joslin
11/10/2004 3:41:02 PM
I have the following "where" clause in a select statement. The @Year
parameter is a string and the @Week parameter is an integer.

WHERE (ColumnYear = @Year) AND (SUBSTRING(ColumnWeek, @Week, 1) = 'X')

When the statement is executed on the data tab of the designer, the
following message is displayed: (The @Year parameter works fine. 2 was
entered as the @Week parameter)

Argument data type varchar is invalid for argument 2 of substring function.

Is this not allowed, or is the syntax incorrect?

Thanks,

John
Alien2_51
11/10/2004 4:34:02 PM
This works...

declare @week int, @str varchar(50)
set @str = '12345678'
set @week = 2

print substring(@str,@week, 3)


if I do...

declare @week int, @str varchar(50)
set @str = '12345678'
set @week = 2

print substring(@str,'2', 3)

I get..
Server: Msg 8116, Level 16, State 1, Line 5
Argument data type varchar is invalid for argument 2 of substring function.
too...

Try casting explicitly to int in your substring function...

HTH


[quoted text, click to view]
AddThis Social Bookmark Button