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.
| Author |
Topic |
|
kid_on_the_block
Posting Yak Master
172 Posts |
Posted - 2005-12-28 : 21:49:04
|
| hi i have a database named FriendsI have a table there with the name Phone I following is the query Select * from Phone where statuscode = 'Alive'Now i want to use XP_Sendmail EXEC xp_sendmail @recipients = 'myself@myworld.com', @query = 'SELECT * FROM Friends.dbo.Phone where statuscode='Alive' ', @subject = 'Friends that are alive', @message = 'Alive Friends are as follows:', @attach_results = 'TRUE', @width = 250This is giving an erorr (Server: Msg 170, Level 15, State 1, Line 2Line 2: Incorrect syntax near 'Alive'., plz help& when I try it without the quotes it still doesnt work .Please help |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-12-28 : 22:51:15
|
| @query = 'SELECT * FROM Friends.dbo.Phone where statuscode=''Alive'' ',CODO ERGO SUM |
 |
|
|
kid_on_the_block
Posting Yak Master
172 Posts |
Posted - 2005-12-29 : 06:58:39
|
| its giving the following error :- Executed as user: MyMachine\Administrator. ODBC error 207 (42S22) Invalid column name 'Alive'. [SQLSTATE 01000] (Message 18014). The step succeeded. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-12-29 : 08:54:03
|
| What is the code you ran to get this error?CODO ERGO SUM |
 |
|
|
tran008
Starting Member
38 Posts |
Posted - 2005-12-29 : 09:53:28
|
| I could be wrong but Alive should be '''Alive'''.@query = 'SELECT * FROM Friends.dbo.Phone where statuscode='''Alive''' ', |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-12-29 : 10:09:43
|
quote: Originally posted by tran008 I could be wrong but Alive should be '''Alive'''.@query = 'SELECT * FROM Friends.dbo.Phone where statuscode='''Alive''' ',
That would not work. It would be a syntax error.The code I posted was correct. I believe that he made the mistake of using double quotes, instead of pairs of single quotes.CODO ERGO SUM |
 |
|
|
ikrima
Starting Member
2 Posts |
Posted - 2006-02-20 : 05:54:44
|
| use this @query = 'SELECT * FROM Friends.dbo.Phone where statuscode='+char(3)+'Alive'+char(39) |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-02-20 : 06:39:03
|
"char(3)"Close |
 |
|
|
|
|
|
|
|