Solved

SQL 2005, check exist before insert.

Posted on 2009-04-06
2
467 Views
Last Modified: 2012-05-06
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
Comment
Question by:Mr_Bach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Expert Comment

by:Binuth
ID: 24084092
IF NOT EXISTS(Select 1 from tablename where fieldname ='Sample test')
begin
-- insert stmt
end
0
 
LVL 14

Accepted Solution

by:
Binuth earned 500 total points
ID: 24084122
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spx for moving values to new table 5 76
Please help for the below sql query. 1 33
Present Absent from working date rage 11 56
Replication failure 1 31
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu‚Ķ
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question