sql - How to compare row with a column? -
sql - How to compare row with a column? -
create table table1( column1 varchar (100), column2 varchar (100) ) go create table table2( column_for_compare varchar (100) ) go insert table2 values ('column1') insert table2 values ('column2') go
i want check if table1 columns name exists in table2 ,something this: --this should comparing row values in table2 column names in table1
if exists(select column_for_compare table2) , if exists(select column_name syscolumn key bring together systable table_name ='table1') begin print 'match found' end
i hope can see im trying...if not...if seek explain better
you can query user_tab_columns table collumn names
select column_name user_tab_columns table_name = 'table1'
and bring together result table2
select * table2, (select column_name user_tab_columns table_name = 'table1') cnames table2.column_for_compare=cnames.column_name
this table collumn names in table_1 exist in rows in table_2
sql tsql sybase-iq
Comments
Post a Comment