Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

UniqueIdentifiers Expand / Collapse
Author
Message
Posted Thursday, January 6, 2011 1:49 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 8:41 AM
Points: 27, Visits: 76
We have the "update" table with the clients' "client_fk" (format 'ntext') number that relates to the "client_pk" (format 'uniqueidentifier") number residing in the "client_demo" table. When I do a query and try join the tables on these two, I am told that I cannot use the ntext field in a comparison with '=' and it is not compatible with the uniqueidentifier. The actual raw string in the fields are the same. Is there any way around this ?

Thank you !
Post #1044016
Posted Thursday, January 6, 2011 1:56 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, June 6, 2014 7:58 AM
Points: 1,837, Visits: 3,420
Can you change the data type of the ntext column? If it's only storing GUID values, why not use the uniqueidentifier data type?
Post #1044022
Posted Thursday, January 6, 2011 2:34 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 8:41 AM
Points: 27, Visits: 76
You're right...however, I should have explained more...it's not my database. I might be able to download it to my machine but its huge, etc. I'm relatively new to SQL (I mostly use MUMPS). I didn't know if there was any type of on-the-fly conversion type function that I could use in the join. I guess worst case I ceate a temp table to play with.
Post #1044045
Posted Thursday, January 6, 2011 2:55 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 12:46 PM
Points: 6,086, Visits: 7,106
Try using CAST( nTextField AS nVARCHAR(MAX)) = uniqueIDField.

It'll run like a three legged dog, but it should run.



- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1044052
Posted Thursday, January 6, 2011 2:58 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, June 6, 2014 7:58 AM
Points: 1,837, Visits: 3,420
A dirty work-around is to use the CONVERT function to convert the ntext column to a uniqueidentifier in the JOIN expression. If it's not your database and you can't change the design, then that is the only option I can think of.
Keep in mind that if any value in the ntext column cannot be converted to a uniqueidentifier, then you'll get an error.
If that happens your only option is to convert both columns (the ntext and uniqueidentifier) to varchar/nvarchar.

But be careful with this approach. SQL Server will have to build a temporary hash table (in tempdb) for the values produced by the CONVERT function, and this will use extra memory, disk I/O and CPU.
Post #1044056
Posted Thursday, January 6, 2011 3:04 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 8:41 AM
Points: 27, Visits: 76
Thank you everyone !!!!

I'll try it...we have 28 change logs each in their own database that I want to make a lookup file to facilitate a lookup without having to go into the actual system (VB) and go client by client. I will be running this once per change log then from the main database, I can query as need be. If it takes all night to run (while all the users are asleep), so be it.

Again, Thank you !!
Post #1044058
Posted Tuesday, April 16, 2013 12:21 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 7, 2014 8:57 AM
Points: 1, Visits: 14
have found a crude yet effective simple remedy to the implicit guid datatype conversion issue.

I've been working with the problem where a GUID may be a NULL value and causes the error of not being able to convert value of string/char to uniqueidentifier .. from everything I've read so far it basically comes down to order of prescedence .. and that the unique identifier data type superceedes any functions you try to impose to do the val1 = val2 comparision with any form of Cast, Convert or IsNull work around.

What I eventually came up with, and this is going to sound very kindergarden coder so I appologize to all of those of you that are infinately more skilled in this area, just use a replace function call on the two values to remove the "-" in the guid and trim any spaces off and the error will not come up again

I think by saying (replace(rtrim(ltrim(val1,'-','') = (replace(rtrim(ltrim(val2,'-','') and replace(rtirm(ltrim(val1,'-','') and (replace(rtrim(ltrim(isnull(val1,''))),'-','') <> ''
you circumvent the implicit guid/unique identifier conversion and it will run for you
Post #1442926
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse