sql - IF EXISTS conditions within multiple statements joined by a union -


i have been working on problem few hours , feel i'm running in circles.

i writing script check table , old database new 1 , wants see if there differences in tables. have part done want make output easier read. ideally want output happen when there records in table, signifying there differences. if there differences in tables 1, 4 , , 8 output table 1, table 4, table 8. add snippet of code need change stuff because of privacy reasons.

if exists( select 'xyz' tablename,  1 table1cd  left join database2 cl on cl.x= cast(cd.x varchar(100)) , cl.type = 'type1' cl.type null ) select tablename else  union  else if exists( select 'abc' tablename, 1 table3 ca left join database2 cl on cl.x = cast(ca.y varchar(100)) , cl.type = 'type2' cl.type null  ) select tablename else  union  more tables repeating structure 

im still new kinda sql. getting errors when run , keep changing around try figure out im @ wall now.

if need list can maintain in table variable, like:

declare @tables table (tablename varchar(100));   if exists(             select 'xyz' tablename,  1 table1cd              left join database2 cl on cl.x= cast(cd.x varchar(100)) , cl.type = 'type1'             cl.type null ) insert @tables     select 'table1'  if exists(         select 'abc' tablename, 1 table3 ca         left join database2 cl on cl.x = cast(ca.y varchar(100)) , cl.type = 'type2'         cl.type null  ) insert @tables     select 'table3'    select * @tables; 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -