Click here to Skip to main content
15,887,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys, I am updating a report in reporting services and I'm having trouble passing a new paramater in to the sql thats already there the sql:
SQL
Declare @SQL nvarchar(4000)

Set @SQL = '
Select Left(' +Case @LookupNumber When 0 Then 'A' When 1 Then 'B' When 2 Then 'C' End + 'Number,' +Cast(@Length as varchar(2)) +') StartofNumber, 
	Count(*) TotalCalls, Sum(Case Duration When 0 then 0 Else 1 End) TotalConnectedCalls, 
	Sum(Duration)/60 Minutes
From vwCDRSuspense200601 With (Nolock)
Where Carrierid = @CarrierId and Productid = @ProductId and errornumber = 2020 And Group by Left(' +Case @LookupNumber When 0 Then 'A' When 1 Then 'B' When 2 Then 'C' End + 'Number,' +Cast(@Length as varchar(2)) +')
Order By StartofNumber'

exec sp_executesql @SQL,N'@ProductId smallint, @CarrierId smallint', @ProductId, @CarrierId

When I try to add any new paramater say in the where clause And Duration = @Duration the report breaks. Any help is very much apreciated as its been a long day:),
Cheers
Posted
Updated 21-May-12 5:57am
v2

1 solution

Where clause expects for another condition... but "see" Group By clause
SQL
Where Carrierid = @CarrierId and Productid = @ProductId and errornumber = 2020 And Group by Left

Remove And word and everything should be OK.
 
Share this answer
 
Comments
frostcox 21-May-12 15:31pm    
Sorry that was a typo by me I had and duration =@duration and it wouldn't work so I forgot to remove the And when I posted the message so I still have the same issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900