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 |
|
Brigs
Starting Member
2 Posts |
Posted - 2006-12-09 : 10:22:15
|
| Hi,I'm wondering is there a command that I can use to check if a certain value exists in the database? Something that returns true or false perhaps? SELECT * FROM Customers WHERE ID ='1' Ok so that's simple, but how can I return a true or false if '1' is a value that exists in the db?thanks. |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2006-12-09 : 11:25:19
|
[code]if exists(SELECT * FROM Customers WHERE ID ='1')begin -- do stuffend[/code]EDIT: btw, are you really using strings to store your ids? I would change them to ints if I were you. http://www.elsasoft.org |
 |
|
|
Brigs
Starting Member
2 Posts |
Posted - 2006-12-09 : 12:06:38
|
quote: Originally posted by jezemine
if exists(SELECT * FROM Customers WHERE ID ='1')begin -- do stuffend EDIT: btw, are you really using strings to store your ids? I would change them to ints if I were you. http://www.elsasoft.org
Hmm I get a parse error:Parse error: syntax error, unexpected T_STRING, expecting '(' on the line: if exists(SELECT * FROM Customers WHERE ID ='1') I should mention that I'm doing this inside a .php page if that makes any difference? |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2006-12-09 : 16:37:24
|
Are you using MS SQL Server? I don't know what a T_STRING is. http://www.elsasoft.org |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-10 : 15:20:07
|
| I think it is PHP.Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-11 : 06:20:41
|
| If you use Mysql you should post at www.MYSQL.comMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|