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 |
|
novicenovice
Starting Member
4 Posts |
Posted - 2008-06-20 : 07:09:05
|
| there is a table named "USER". I want to check that either user name exists or not in the table.I have two approaches.Approach1: I write a query like Select userName from USER; and then compare the results in C# program and find that either this username exists or not. This approach is not good, as I have to retrieve all the results and then compare.Approach2: ( that what I am looking for??). Is there any way that I simply write a SQL query and it tells me that either this username exists or not. I have listen about SQL functions but don't know in detail about them.please give a detailed answers and I appreciate if you provide me an example code. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-06-20 : 07:48:34
|
| You could tryIF EXISTS(select * from user here username = @username)BEGIN<do stuff>END Jim |
 |
|
|
pkokkula
Starting Member
3 Posts |
Posted - 2008-06-21 : 02:16:34
|
| HaiA little chage in the StatementIF EXISTS(select 1 from user here username = @username)BEGIN<do stuff>ENDPavan Kokkulahttp://www.ggktech.com/ |
 |
|
|
|
|
|