You can use the Set Operators - UNION (Transact-SQL) to concatenate the result of two queries.
But for this it's mandatory that both (or more) queries returns the same count of columns and data types.
display one result with while in sql

hello ,
please i'm trying this code in sql and i want the result to be in one table not in different table
3 answers
Sort by: Most helpful
-
Olaf Helper 29,021 Reputation points
2021-09-14T11:27:26.147+00:00 -
Olaf Helper 29,021 Reputation points
2021-09-14T11:38:04.377+00:00 display one result with while in sql
I missed your WHILE loop; that's when one post images instead of code.
Why a loop?
You can insert the query result into a temp table or table variable and query the result at the end of your loop. -
MelissaMa-MSFT 24,136 Reputation points
2021-09-15T01:14:17.627+00:00 Hi @asma gh ,
Welcome to Microsoft Q&A!
It is recommended for you to post the complete query together with CREATE TABLE statements for your tables together with INSERT statements with sample data instead of snapshot.
You could have a try to create one template table and store all results under loop into this template table.
Please refer below example:
DROP TABLE IF EXISTS #temp create table #temp (ADATE DATE,ID INT,DATEE DATE) declare @i date set @i='2021-01-01' while (@i<='2021-01-31') begin insert into #temp select @i,id, convert(date,CONCAT... from dbo.ods_arrangment arr where convert... set @i=DATEADD(day,7,@i) end select * from #temp
Since your snapshot is not a complete one, please fulfill above ellipsis part with your actual one.
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.