Solved

SQL 2005, check exist before insert.

Posted on 2009-04-06
2
460 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

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!

Question has a verified solution.

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

Suggested Solutions

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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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