Solved

SQL 2005, check exist before insert.

Posted on 2009-04-06
2
419 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
  • 2
2 Comments
 
LVL 14

Expert Comment

by:Binuth
Comment Utility
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
Comment Utility
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now