select name col1 from syscolumns where id=object_id (' TableName1)
Id
The username
The status
select name col2 from syscolumns where id=object_id (' TableName2)
Uid
"
Area
Street
Num
Query of the two tables all columns (the number of columns), how to combine two of the query results as a table, make the query results into a table of two fields,
Id uid
The username password
The status area
Street
Num
Consult everybody a great god
CodePudding user response:
Union allCodePudding user response:
As with m (
Select row_number () over rn order by id, name, 'x
The from syscolumns where id=3
Union all
Select row_number () over (order by id) rn, 'x, name
The from sysobjects where id=55
)
Select an rn, MAX (name) c2, MAX c3 group by an rn from m (x)
Rn c2 c3
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1 rsid sysiscols
2 rscolid
3 hbcolid
4 rcmodified
Five ti
6 cid
7 ordkey
8 maxinrowlen
The status of 9
10 offset
11 nullbit
12 bitpos
13 colguid
14 dbfragid
(14) affected
CodePudding user response:
Union all after only one column, requested the query results as two columns of the output,CodePudding user response:
; WITH tempa AS (
SELECT the name col1, ROW_NUMBER () OVER (ORDER BY name) num
The FROM syscolumns
WHERE id=OBJECT_ID (' TableName1)
), tempb AS (
SELECT the name col1, ROW_NUMBER () OVER (ORDER BY name) num
The FROM syscolumns
WHERE id=OBJECT_ID (' TableName2)
)
The SELECT tempa col1,
Tempb. Col1
The FROM tempa
FULL JOIN tempb ON tempb. Num=tempa. Num
CodePudding user response:
Cross the applyCodePudding user response: