SQL Server Table Display Result

I have a SQL column Employee_Id, I want to display all data of this column in two equally divided column in one table by using query.?
Varun GaurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dorababu MSenior Software EngineerCommented:
Any sample output of what you are expecting and what is the table structure?
Dustin SaundersDirector of OperationsCommented:
No idea what the practical application of this is?

Anyways, you can do this with a temp table.  Create a temp table and select row number and an integer value to pair them-- then you can get this result.

Full Sample:
CREATE TABLE #sampledata (id int)
DECLARE @start int = 1
DECLARE @end int = 250
WHILE @start <= @end
BEGIN
	INSERT INTO #sampledata (id) VALUES (@start)
	SET @start = @start + 1
END

CREATE TABLE #temp (row int, pair INT, id VARCHAR(100))

INSERT INTO #temp (row, pair, id)
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS "row",(ROW_NUMBER() OVER (ORDER BY (SELECT 0)))/2.0 + 0.5 AS "pair",id FROM #sampledata

SELECT t1.id AS "columnA", t2.id AS "columnB"
FROM #temp t1
LEFT JOIN #temp t2 ON t1.pair = t2.pair AND t2.row % 2 = 0
WHERE t1.row % 2 != 0

DROP TABLE #sampledata
DROP TABLE #temp

Open in new window


Functional Code:
CREATE TABLE #temp (row int, pair INT, id VARCHAR(100))

INSERT INTO #temp (row, pair, id)
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS "row",(ROW_NUMBER() OVER (ORDER BY (SELECT 0)))/2.0 + 0.5 AS "pair",id FROM #sampledata

SELECT t1.id AS "columnA", t2.id AS "columnB"
FROM #temp t1
LEFT JOIN #temp t2 ON t1.pair = t2.pair AND t2.row % 2 = 0
WHERE t1.row % 2 != 0

DROP TABLE #temp

Open in new window


Result:
columnA	columnB
1	2
3	4
5	6
7	8
9	10
11	12
13	14
15	16
17	18
19	20
21	22
23	24
25	26
27	28
29	30
31	32
33	34
35	36
37	38
39	40
41	42
43	44
45	46
47	48
49	50
51	52
53	54
55	56
57	58
59	60
61	62
63	64
65	66
67	68
69	70
71	72
73	74
75	76
77	78
79	80
81	82
83	84
85	86
87	88
89	90
91	92
93	94
95	96
97	98
99	100
101	102
103	104
105	106
107	108
109	110
111	112
113	114
115	116
117	118
119	120
121	122
123	124
125	126
127	128
129	130
131	132
133	134
135	136
137	138
139	140
141	142
143	144
145	146
147	148
149	150
151	152
153	154
155	156
157	158
159	160
161	162
163	164
165	166
167	168
169	170
171	172
173	174
175	176
177	178
179	180
181	182
183	184
185	186
187	188
189	190
191	192
193	194
195	196
197	198
199	200
201	202
203	204
205	206
207	208
209	210
211	212
213	214
215	216
217	218
219	220
221	222
223	224
225	226
227	228
229	230
231	232
233	234
235	236
237	238
239	240
241	242
243	244
245	246
247	248
249	250

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Varun GaurAuthor Commented:
thanks, sir.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.