sql - Only select rows if at least one exists -
i have next query:
if exists ( select column1 , column2 dbo.table1 except select column1 , column2 @proposeddata ) begin select column1 , column2 dbo.table1 except select column1 , column2 @proposeddata raiserror('unexpected values in proposed data',16,10) end
i want raise error if info exists in table not appear in table variable. create sure source code matches in particular environment. problem 2 select queries duplicate code. introduces possibility human error - 2 queries should same different. alternative is:
select column1 , column2 dbo.table1 except select column1 , column2 @proposeddata if @@rowcount <> 0 begin raiserror ('invalid objecttype values',16,10) end
however 'pollutes' query output there empty result set if info correct. so, there way prevent result set beingness output if there 0 rows? thought stored proc takes select , constructs first illustration query wondering there built in way it.
thanks joe
how ?
if exists(select column1 , column2 dbo.table1 except select column1 , column2 @proposeddata) raiserror ('invalid objecttype values',16,10)
sql sql-server tsql
No comments:
Post a Comment