Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

SQL 2005, check exist before insert.

Please tell me how can I check existing data before insert new value.
for example: in my database has this value:   Sample Test.
So when user input new values like: sample test, Sample Test, Sample test, sample Test. SQL will prevent it.

How can I do?
Please help me!
0
Mr_Bach
Asked:
Mr_Bach
  • 2
1 Solution
 
BinuthCommented:
IF NOT EXISTS(Select 1 from tablename where fieldname ='Sample test')
begin
-- insert stmt
end
0
 
BinuthCommented:
use COLLATE SQL_Latin1_General_CP1_CI_AS - for non- case senstive search
IF NOT EXISTS (SELECT 1 FROM TableName WHERE feildName COLLATE SQL_Latin1_General_CP1_CI_AS = 'Sample Test' )
BEGIN
 
	-- Insert Statement
 
END

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now