Howto SELECT for GUID values in a column.

R

Ron Allen

As in the subject, how do I form a Select clause for a given GUID column in
SQL Server. For some reason I can't get the syntax correct for this. I
tried searching as a string with both { } bracketing the string and without
the braces but I'm getting an exception (syntax error) thrown.
I'm searching a list of labor categories each of which is attached to a
given CLIN item. Both PK fields on these are GUIDs. I'm trying to find all
the LaborCat rows with a given CLIN.

Ron Allen
 
A

Andy Gaskell

SELECT * FROM LaborCat WHERE Column= 'GUID HERE'

Example:

SELECT * FROM LaborCat WHERE Column = '073BD073-66BB-4A0B-BABD-8E26FAB6154C'
 
R

Ron Allen

Andy,
That's what I thought but when I put this query into QueryAnalyzer and
put in a CLIN Guid value from the table I get no results.
The actual query is
SELECT lcKey, clinKey, Cat, CatDesc, CatRate, CatHrs, PerfLocation,
ValidFrom, ValidTo, LastUpdate
FROM LaborCats
WHERE lcKey = '5DC2179A-4106-4DC2-AAEE-0FE856366994';
Where I have just copied the Guid value from the LaborCats table in the
clinKey column. QueryAnalyzer just reports (0 row(s) affected) with no
data. The syntax is fine I just receive no results.

Ron Allen
 
A

Andy Gaskell

I might be misunderstanding here, but if you copied the value
'5DC2179A-4106-4DC2-AAEE-0FE856366994' from the clinKey column, then your
where clause is incorrect.

Try this where clause:
WHERE clinKey = '5DC2179A-4106-4DC2-AAEE-0FE856366994'
 
R

Ron Allen

Andy,
Yes, you're right (slapping self on head). All that trouble for a
mistype in the test query. Of course I meant to put in "clinKey = 'xxxx'"
so that's how I was reading it.
Thanks,
Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top