| | |
Query database to see if value already exists one statment
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 26
Reputation:
Solved Threads: 1
Hello,
While working on setting up user accounts, I wanted to see if the values already existed in a database to alert the user before submitting the data. While doing this, I came to an issue. The issue is when I went the MS SQL SMS and tried writing a test query, I couldn't figure out how to write it in one select statment.
Now the issue comes in when I try to move this code over to C#. I am trying to do this with out creating stored procedures because I have many different tables and columns and would prefer writing the code on the System.Data.SqlClient.SqlCommand. Or the best solution is writing a stored procedure where could I make the "FROM Table" and "WHERE Column" parameters passed in from C#
Thanks for all the help,
Johnny
While working on setting up user accounts, I wanted to see if the values already existed in a database to alert the user before submitting the data. While doing this, I came to an issue. The issue is when I went the MS SQL SMS and tried writing a test query, I couldn't figure out how to write it in one select statment.
MS SQL Syntax (Toggle Plain Text)
DECLARE @maybe bit IF EXISTS( SELECT * FROM UserList WHERE UserName = 'Tester') SET @maybe = 1 ELSE SET @maybe = 0 SELECT @maybe
Now the issue comes in when I try to move this code over to C#. I am trying to do this with out creating stored procedures because I have many different tables and columns and would prefer writing the code on the System.Data.SqlClient.SqlCommand. Or the best solution is writing a stored procedure where could I make the "FROM Table" and "WHERE Column" parameters passed in from C#
Thanks for all the help,
Johnny
•
•
Join Date: Feb 2008
Posts: 42
Reputation:
Solved Threads: 13
maybe you can use CASE ... WHEN ... END command like below:
MS SQL Syntax (Toggle Plain Text)
SELECT cast(case when EXISTS (SELECT * FROM UserList WHERE UserName = 'Tester') then 1 else 0 end AS bit)
Hence Wijaya
www.ex-Soft.tk
www.ex-Soft.tk
![]() |
Similar Threads
- determining if an SQL database exists, etc. (MS SQL)
- Query regarding Database design (Database Design)
- Monitor Database or Monitor Filesystem? (Computer Science)
- How to query database through javascripts (JavaScript / DHTML / AJAX)
- Query database (MS Access and FileMaker Pro)
- help wif uploading My sql database into Phpmyadmin.com (MySQL)
- query problem (delimiter?) (PHP)
- HOWTO: Run a Query on a Database using ODBC and return all Results into a DGV Object (C#)
- JSP Problem Student database search (Java)
Other Threads in the MS SQL Forum
- Previous Thread: HELP!!! Converting Hexadecimal to Decimal or vice versa
- Next Thread: Problem restoring Database after Backup
| Thread Tools | Search this Thread |





