Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Syntax for IF THEN Error if Field Above Value?

Author  Topic 

Palermo
Starting Member

25 Posts

Posted - 2013-10-28 : 16:49:36
I have a set of values in a field and want to display an error using IF THEN e.g.

SELECT table1.column
FROM table1
IF table1.column > 80
RAISERROR ('Value is too high. Please ammend', 16, 1)

I get the following error :

The multi-part identifier could not be bound.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-28 : 17:19:13
If you are looking for at least one value in that table that exceeds 80, then do it like this:
IF EXISTS (SELECT * FROM Table1 WHERE column1 > 8)
RAISERROR('At least one value is too high, please amend', 16,1)
Go to Top of Page

Palermo
Starting Member

25 Posts

Posted - 2013-10-28 : 17:29:11
Thank you.
Go to Top of Page
   

- Advertisement -