|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 28,
Visits: 212
|
|
Hello I keep getting the above error when running this script.
any ideas? It's driving me nuts! It's probably something simple but it's been a very long week!
It seems to be something to do with line 17, it's the bold text for ease
DECLARE @dates VARCHAR(100) declare @jobid VARCHAR(max) = ('101038, 101039, 101040, 101044')
DECLARE @Tmp TABLE(JobIDs VARCHAR(40)) INSERT INTO @Tmp (JobIds) SELECT CAST(Items AS VARCHAR(40)) FROM InterfaceSystem.dbo.fn_SplitString(@jobid,',')
SELECT @dates = COALESCE (@dates ,'') + CONVERT(VARCHAR(100),i.itt_appointmentdateandtime, 103) +',' FROM LibertyGasGroup_MSCRM.dbo.FilteredITT_instruction I WHERE i.itt_jobcodeid in (select JobIDs from @Tmp) AND (i.itt_outcome = 2) GROUP BY i.itt_appointmentdateandtime select distinct i.itt_outcome , j.itt_id , substring(@dates, 1, charindex(',', @dates)-1) as date1 , substring(@dates, 12, charindex(',', @dates)-1) as date2 , substring(@dates, 23, charindex(',', @dates)-1) as date3 , substring(@dates, 34, charindex(',', @dates)-1) as date4 from LibertyGasGroup_MSCRM.dbo.FilteredITT_instruction i inner join LibertyGasGroup_MSCRM.dbo.FilteredITT_job j on j.ITT_jobId = i.itt_jobcodeid where (i.itt_outcome = 2) and i.itt_jobcodeid in (select JobIDs from @Tmp)
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:55 PM
Points: 15,442,
Visits: 9,571
|
|
Not really enough here to help you out. At the very least, I'd need to see the definition of your split string function, and probably the table definitions.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 5,615,
Visits: 10,983
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 28,
Visits: 212
|
|
Hi,
the datatype of the all of the id columns are uniqueidentifiers within the database. However these values are being passed to the SP from SSRS as a multi value parameter value. Hence the split function.
I've tried casting the id's as uniqueidentifiers as seen below but with no luck.
DECLARE @dates VARCHAR(100) declare @jobid uniqueidentifier = ('d63b6001-59fd-e111-94eb-001517a81d9d, a149467b-b9f5-e111-94eb-001517a81d9d, 441ca81a-bdf5-e111-94eb-001517a81d9d, d28923b2-bcf5-e111-94eb-001517a81d9d')
DECLARE @Tmp TABLE(JobIDs VARCHAR(40)) INSERT INTO @Tmp (JobIds) SELECT CAST(Items AS uniqueidentifier) FROM InterfaceSystem.dbo.fn_SplitString(@jobid,',')
SELECT @dates = COALESCE (@dates ,'') + CONVERT(VARCHAR(100),i.itt_appointmentdateandtime, 103) +',' FROM LibertyGasGroup_MSCRM.dbo.FilteredITT_instruction I WHERE i.itt_jobcodeid in (select JobIDs from @Tmp) AND (i.itt_outcome = 2) GROUP BY i.itt_appointmentdateandtime select distinct i.itt_outcome , j.itt_id , substring(@dates, 1, charindex(',', @dates)-1) as date1 , substring(@dates, 12, charindex(',', @dates)-1) as date2 , substring(@dates, 23, charindex(',', @dates)-1) as date3 , substring(@dates, 34, charindex(',', @dates)-1) as date4 from LibertyGasGroup_MSCRM.dbo.FilteredITT_instruction i inner join LibertyGasGroup_MSCRM.dbo.FilteredITT_job j on j.ITT_jobId = i.itt_jobcodeid where (i.itt_outcome = 2) and i.itt_jobcodeid in (select JobIDs from @Tmp) I was playing round with the shorter values to see if that would make any difference.
this is typically how the values would be passed back from SSRS
'd63b6001-59fd-e111-94eb-001517a81d9d, a149467b-b9f5-e111-94eb-001517a81d9d, 441ca81a-bdf5-e111-94eb-001517a81d9d, d28923b2-bcf5-e111-94eb-001517a81d9d'
unless of course there is a better way to pass them through..?
here's the split function
ALTER function [dbo].[fn_SplitString] ( @String nvarchar(MAX), @Delimiter char(1) ) Returns @Results Table (Items nvarchar(4000)) As Begin Declare @Index int Declare @Slice nvarchar(4000) Select @Index = 1 If @String Is NULL Return While @Index != 0 Begin Select @Index = CharIndex(@Delimiter, @String) If (@Index != 0) Select @Slice = left(@String, @Index - 1) else Select @Slice = @String Insert into @Results(Items) Values (@Slice) Select @String = right(@String, Len(@String) - @Index) If Len(@String) = 0 break End Return End
thanks in advance
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 10:26 PM
Points: 8,606,
Visits: 8,247
|
|
The problem is because you have a list of numbers and you are trying to compare that to a uniqueidentifier.
You insert this into a table. ('101038, 101039, 101040, 101044')
INSERT INTO @Tmp (JobIds) SELECT CAST(Items AS VARCHAR(40)) FROM InterfaceSystem.dbo.fn_SplitString(@jobid,',')
But then you try to find them in your table. Assuming itt_jobcodeid is a uniqueidentifier you are comparing apples to oranges here. It will attempt to cast your values to a uniqueidentifier and those are not valid values.
and i.itt_jobcodeid in (select JobIDs from @Tmp)
As a side note, I would highly recommend reading the article linked in my signature about splitting strings. It will blow the doors off the while loop splitter.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Moden's splitter.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: 2 days ago @ 2:39 AM
Points: 28,
Visits: 212
|
|
Thanks Sean,
I've tried it a few ways casting as unique identifiers and varchars and none of them seem to be working. I was only playing round with the shorter values and forgot to edit them out of my post 
I think I may be barking up the wrong tree with this solution anyway but I'll need to split the values out anyway so I'll read the split article shortly.
edit: Thanks, you were all right. Apologies, it's a friday afternoon. Regards
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 8:34 AM
Points: 23,
Visits: 49
|
|
@Qutip I also face the same issue with GUIDs. Use Jeff's Splitter. It is awesome. I converted the GUID column to varchar and it worked. Try it out
cast(<GUIDColumn> as varchar(max)) IN (SELECT Item FROM dbo.udf_Split(@ParamVariable, ','))
|
|
|
|