March 12, 2024 at 8:22 am
I have 1 record(1row*2columns) from 1 select
and
a different select which can result in multiple rows but will always have 3 columns.
How can I repeat the 1 row next to the result set from the second select.
No common columns from these 2 selects...
March 12, 2024 at 8:34 am
Your final resultset cannot contain a mixture of numbers of columns and datatypes. But you can create a wider dataset, eg
SELECT Col1, Col2, Col3, Col4 = NULL, Col5 = NULL
from qry1
UNION ALL
SELECT Col1 = NULL, Col2 = NULL, Col3 = NULL, Col4, Col5
from qry2
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
March 12, 2024 at 9:33 am
My first select :
A E:\1.mdf D
A_1 E:\2_1.ndf D
A_log F:\3.ldf L
My second select:
SrvA Db1
This is what the result looked like from the query posted. Thank you for this...but
A E:\1.mdf D NULL NULL
A_1 E:\2_1.ndf D NULL NULL
A_log F:\3.ldf L NULL NULL
NULL NULL NULL SrvA Db1
...This is what I need
A E:\1.mdf D SrvA Db1
A_1 E:\2_1.ndf D SrvA Db1
A_log F:\3.ldf L SrvA Db1
March 12, 2024 at 10:40 am
this is why you should supply consumable data and desired output.
so on above example, how do we link between tbl1 and tbl2? this is assuming that there are more than 1 rows on tbl2
March 12, 2024 at 10:50 am
Like this?
WITH qry1
AS (SELECT *
FROM
(
VALUES
('SrvA', 'Db1')
) x(Col4, Col5) )
,qry2
AS (SELECT *
FROM
(
VALUES
('A', 'E:\1.mdf', 'D')
,('A_1', 'E:\2_1.ndf', 'D')
,('A_log', 'F:\3.ldf ', 'L')
) y(Col1, Col2, Col3) )
SELECT qry2.Col1
,qry2.Col2
,qry2.Col3
,qry1.Col4
,qry1.Col5
FROM qry2
CROSS JOIN qry1;
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
March 12, 2024 at 4:21 pm
I have 1 record(1row*2columns) from 1 select
and
a different select which can result in multiple rows but will always have 3 columns.
How can I repeat the 1 row next to the result set from the second select.
No common columns from these 2 selects...
Dude... readily consumable data and desired result output, please! I see you finally provided some but you shouldn't need to be reminded with every post. And, no... I'm not trying to be mean... I'm trying to tell you how to help yourself.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply