Home > database >  Consult a great god, and how the two SQL column data at the same time, there is another table
Consult a great god, and how the two SQL column data at the same time, there is another table

Time:04-30

Listed in table a station and cause two field data, I think in the decision table in table b a station and the cause of both field data exist, there is no wrote in table b, thank you

CodePudding user response:

 insert into b (field name) 
The select val
The from (
Select *
From a
Unpivot (val for col (station, cause)) in p
) a
Where not the exists (1 from the select top 1 b where the field name=Dr. Al)


Both post and post bar

CodePudding user response:

 
Insert into table b (station, cause)
The select a.s tation, a.c ause
A. the from list a
Left the join table b b
On a.s tation=b.s tation
And a.c ause=biggest ause
Where b.s tation is null

CodePudding user response:

 
The MERGE INTO target b
USING a source
ON (target) station=source) station AND target. Cause=source. The cause)
WHEN NOT MATCHED THEN
INSERT (station, cause) VALUES (source) station, the source, cause);

CodePudding user response:

refer to the original poster tianxia978 response:
listed in table a station and cause two field data, I think in the decision table in table b a station and the cause of both field data exist, there is no wrote in table b, thanks


 
If not the exists (select 1 from syscolumns inner join sysobjects on sysobjects. Id=syscolumns. Id
Where syscolumns. Name='station' and syscolumns. Name='cause' and sysobject. The table name="B '
The begin
The update B...

End
  • Related