﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / Conversion failed when converting from a character string to uniqueidentifier. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 10:50:07 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>@QutipI 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 outcast(&amp;lt;GUIDColumn&amp;gt; as varchar(max)) IN (SELECT Item FROM dbo.udf_Split(@ParamVariable, ','))</description><pubDate>Mon, 12 Nov 2012 10:43:45 GMT</pubDate><dc:creator>sivapragasam2000</dc:creator></item><item><title>RE: Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>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 :w00t: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</description><pubDate>Fri, 28 Sep 2012 08:31:24 GMT</pubDate><dc:creator>Qutip</dc:creator></item><item><title>RE: Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>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')[code]INSERT INTO @Tmp (JobIds)		SELECT CAST(Items AS VARCHAR(40)) FROM InterfaceSystem.dbo.fn_SplitString(@jobid,',')[/code]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.	[code]and i.itt_jobcodeid  in (select JobIDs from @Tmp)[/code]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.</description><pubDate>Fri, 28 Sep 2012 08:20:47 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>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.[code="sql"]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 date4from		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)[/code]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[code="sql"]ALTER function [dbo].[fn_SplitString](	@String nvarchar(MAX),	@Delimiter char(1)) Returns @Results Table (Items nvarchar(4000))AsBegin	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		EndReturnEnd[/code]thanks in advance</description><pubDate>Fri, 28 Sep 2012 07:59:29 GMT</pubDate><dc:creator>Qutip</dc:creator></item><item><title>RE: Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>What's the datatype of column [itt_jobcodeid], table [LibertyGasGroup_MSCRM].dbo.[FilteredITT_instruction]?</description><pubDate>Fri, 28 Sep 2012 07:38:14 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>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.</description><pubDate>Fri, 28 Sep 2012 07:01:25 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>Conversion failed when converting from a character string to uniqueidentifier.</title><link>http://www.sqlservercentral.com/Forums/Topic1365837-392-1.aspx</link><description>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  [code="sql"]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,',')		[b]SELECT @dates = COALESCE	(@dates ,'')  + CONVERT(VARCHAR(100),i.itt_appointmentdateandtime, 103) +','[/b]				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 date4from		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)[/code]</description><pubDate>Fri, 28 Sep 2012 06:37:43 GMT</pubDate><dc:creator>Qutip</dc:creator></item></channel></rss>