Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Please Help!!!

Author  Topic 

Tricia
Starting Member

4 Posts

Posted - 2007-05-04 : 12:35:03
This is my query:

SELECT convert(prospects.prospectid as int(8)) as Prospect, trialSessions.experienceCode, prospects.email
FROM trialSessions
JOIN prospects ON trialSessions.prospectID = prospects.prospectid

I'm getting this error message:
Incorrect syntax near the keyword 'as'

Can someone tell me what I'm missing :)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-04 : 12:37:03
convert(bigint, prospects.prospectid)
or
cast(prospects.prospectid as bigint)

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-04 : 12:37:13
quote:
Originally posted by Tricia

This is my query:

SELECT cast(prospects.prospectid as int(8)) as Prospect, trialSessions.experienceCode, prospects.email
FROM trialSessions
JOIN prospects ON trialSessions.prospectID = prospects.prospectid

I'm getting this error message:
Incorrect syntax near the keyword 'as'

Can someone tell me what I'm missing :)



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Tricia
Starting Member

4 Posts

Posted - 2007-05-04 : 12:50:10
Now I'm getting this error:

Conversion failed when converting the varchar value '3C1F1C44-CC6D-44F6-9077-9E4EFB8244EC' to data type int.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-04 : 13:04:16
you want to convert the string '3C1F1C44-CC6D-44F6-9077-9E4EFB8244EC' into integer ?


KH

Go to Top of Page

Tricia
Starting Member

4 Posts

Posted - 2007-05-04 : 13:07:03
What I actually want to convert this to is to a numeric but I can't seem to get this to work either as an int, varchar or numeric. I know I'm missing something but am at a loss. I really appreciate anyhelp.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-04 : 13:08:49
and how do you want this conversion to work logicaly??

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-04 : 13:27:10
quote:
but am at a loss

You are not alone there.
How do you expect to convert a string like '3C1F1C44-...' to numeric ?

What is this string anyway ? What is the purpose of "converting" it to numeric ?


KH

Go to Top of Page

sshelper
Posting Yak Master

216 Posts

Posted - 2007-05-04 : 13:46:59
How about doing it this way:

SELECT CAST(CAST('3C1F1C44-CC6D-44F6-9077-9E4EFB8244EC' AS VARBINARY) AS INT)

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-05-05 : 02:10:25
Am I on the wrong end of the stick here?

Its a GUID, and thus could be converted to either a Uniqueidentifier, or, if you must, a 16-byte binary:

SELECT CONVERT(uniqueidentifier, '3C1F1C44-CC6D-44F6-9077-9E4EFB8244EC')
SELECT CONVERT(varbinary(16), CONVERT(uniqueidentifier, '3C1F1C44-CC6D-44F6-9077-9E4EFB8244EC'))

Or even, maybe:

SELECT CONVERT(bigint, CONVERT(varbinary(16), CONVERT(uniqueidentifier, '3C1F1C44-CC6D-44F6-9077-9E4EFB8244EC')))

Kristen
Go to Top of Page
   

- Advertisement -