Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 setting the right order

Author  Topic 

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2012-02-28 : 15:43:06
i have following example:

create table #int
(id int identity(1,1)
,num tinyint);
GO

insert into #int (num)
select 1;
go 100

select * from #int


create table #t
(id int identity(1,1)
,te varchar(10)
);
GO

insert into #t (te)
select '1111' union all
select '2222' union all
select '3333' union all
select '4444'


and i want to have result expected as:
id te
--------
1 1111
2 2222
3 3333
4 4444
5 1111
6 2222
7 3333
8 4444
9 1111
10 2222
11 3333
...

there should be a simple solution. but just can't remember it know :(

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-28 : 15:48:54
[code]
SELECT i.id,t.te
FROM #t t
CROSS JOIN #int i
WHERE (i.id-1)%4 = t.id -1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2012-02-28 : 15:52:16
yes. MOD :) i forgot.

thank you Visakh16
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-28 : 16:13:41
GO 100????

HOLY CRAP

Another "Feature"



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-28 : 18:28:19
quote:
Originally posted by X002548

GO 100????

HOLY CRAP

Another "Feature"



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/





yep...from 2005 onwards

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -