|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
INSERT queryI have a very basic query question. I have two tables tblabc and tblxyz. tblabc has three col abcid, abc1, abc2 tblxyz has three col xyzid xyz1 xyz2 I want to insert value in tblabc from tblxyz where xyz1 like '%OPEN' (do not want xyzid and xyz2) with this I want to insert abc2 as 'ENABLED' so reading the BOL, I see a query that can help me insert xyz1 USE mydb INSERT INTO tblabc SELECT xyz1 FROM xyz WHERE xyz1 like '%OPEN' but where can I set abc2 value 'ENABLED' in one single query? I can do two query and then do the update but I want to learn how I can do this in one shot. Thank you, hj INSERT INTO tblabc (abc1, abc2)
SELECT xyz1,'ENABLED' FROM xyz WHERE xyz1 like '%OPEN' Denis the SQL Menace http://sqlservercode.blogspot.com/ Hitesh wrote: Show quote > Hi, > > I have a very basic query question. > I have two tables tblabc and tblxyz. > > tblabc has three col abcid, abc1, abc2 > tblxyz has three col xyzid xyz1 xyz2 > > I want to insert value in tblabc from tblxyz where xyz1 like '%OPEN' > (do not want xyzid and xyz2) with this I want to insert abc2 as > 'ENABLED' > > so reading the BOL, I see a query that can help me insert xyz1 > USE mydb > INSERT INTO tblabc > SELECT xyz1 > FROM xyz > WHERE xyz1 like '%OPEN' > > but where can I set abc2 value 'ENABLED' in one single query? I can do > two query and then do the update but I want to learn how I can do this > in one shot. > > Thank you, > hj Thank you. That worked like a charm.
hj SQL Menace wrote: Show quote > INSERT INTO tblabc (abc1, abc2) > SELECT xyz1,'ENABLED' > FROM xyz > WHERE xyz1 like '%OPEN' > > Denis the SQL Menace > http://sqlservercode.blogspot.com/ > > > Hitesh wrote: > > Hi, > > > > I have a very basic query question. > > I have two tables tblabc and tblxyz. > > > > tblabc has three col abcid, abc1, abc2 > > tblxyz has three col xyzid xyz1 xyz2 > > > > I want to insert value in tblabc from tblxyz where xyz1 like '%OPEN' > > (do not want xyzid and xyz2) with this I want to insert abc2 as > > 'ENABLED' > > > > so reading the BOL, I see a query that can help me insert xyz1 > > USE mydb > > INSERT INTO tblabc > > SELECT xyz1 > > FROM xyz > > WHERE xyz1 like '%OPEN' > > > > but where can I set abc2 value 'ENABLED' in one single query? I can do > > two query and then do the update but I want to learn how I can do this > > in one shot. > > > > Thank you, > > hj |
|||||||||||||||||||||||