Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL that generates a sequence

 
   Database Help (Home) -> MSEQ RSS
Next:  Searching a table and displaying the results in M..  
Author Message
Yuri

External


Since: Nov 17, 2008
Posts: 1



(Msg. 1) Posted: Mon Nov 17, 2008 11:39 am
Post subject: SQL that generates a sequence
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

Hello,
I need to create a query that will return a sequence of numbers, something
like this:
1
2
3
....
99
100

Please help
Thanks,
Yuri

 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Lawrence Garvin

External


Since: Oct 16, 2008
Posts: 16



(Msg. 2) Posted: Tue Nov 18, 2008 3:12 pm
Post subject: Re: SQL that generates a sequence [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Yuri" wrote in message

> Hello,
> I need to create a query that will return a sequence of numbers, something
> like this:
> 1
> 2
> 3
> ...
> 99
> 100
>
> Please help
> Thanks,
> Yuri


declare @i int
declare @maxvalue int

set @i = 1
set @maxvalue = 100

while @i <= @maxvalue
begin
select @i
set @i = @i + 1
end




--
Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
Principal/CTO, Onsite Technology Solutions, Houston, Texas

 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Yuri Den

External


Since: Nov 17, 2008
Posts: 4



(Msg. 3) Posted: Wed Nov 19, 2008 9:39 am
Post subject: Re: SQL that generates a sequence [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks Lawrence, but that is not what I need.
I need single query Select statement. On Oracle it looks like this:
SELECT LEVEL FROM DUAL

CONNECT BY LEVEL <= 100



"Lawrence Garvin" wrote in message

> "Yuri" wrote in message
>
>> Hello,
>> I need to create a query that will return a sequence of numbers,
>> something
>> like this:
>> 1
>> 2
>> 3
>> ...
>> 99
>> 100
>>
>> Please help
>> Thanks,
>> Yuri
>
>
> declare @i int
> declare @maxvalue int
>
> set @i = 1
> set @maxvalue = 100
>
> while @i <= @maxvalue
> begin
> select @i
> set @i = @i + 1
> end
>
>
>
>
> --
> Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
> Principal/CTO, Onsite Technology Solutions, Houston, Texas
 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Lawrence Garvin

External


Since: Oct 16, 2008
Posts: 16



(Msg. 4) Posted: Wed Nov 19, 2008 3:45 pm
Post subject: Re: SQL that generates a sequence [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Yuri Den" wrote in message


>>> Hello,
>>> I need to create a query that will return a sequence of numbers,
>>> something
>>> like this:
>>> 1
>>> 2
>>> 3
>>> ...
>>> 99
>>> 100


>> declare @i int
>> declare @maxvalue int
>>
>> set @i = 1
>> set @maxvalue = 100
>>
>> while @i <= @maxvalue
>> begin
>> select @i
>> set @i = @i + 1
>> end


> Thanks Lawrence, but that is not what I need.
> I need single query Select statement. On Oracle it looks like this:

> SELECT LEVEL FROM DUAL
> CONNECT BY LEVEL <= 100

Yeah.. well, this ain't Oracle, and you got an answer befitting your
question.

Your query won't provide anything unless there's a table populated with
data.

Now, if you'd like to provide *additional* constraints to your question...
Like, maybe, the data is already in a table and you're trying to retreive
data from the table???

Then maybe something as basic as
SELECT <column> FROM <table> WHERE <column> <= 100 ORDER BY <column>

But then... if we're asking questions this simple,
your better source for help is probably a book named something like
"Teach Yourself T-SQL in Seven Days".

Do you have a real *problem* to solve, or do you just not know anything
about T-SQL?


--
Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
Principal/CTO, Onsite Technology Solutions, Houston, Texas
 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Yuri Den

External


Since: Nov 17, 2008
Posts: 4



(Msg. 5) Posted: Wed Nov 19, 2008 3:45 pm
Post subject: Re: SQL that generates a sequence [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Lawrence, I love your answer! What an elegant solution Smile
SELECT <column> FROM <table> WHERE <column> <= 100 ORDER BY <column>

In case if someone else encountered with similar problem, here is link to
solution:
http://www.projectdmx.com:80/tsql/tblnumbers.aspx

Thanks,
Yuri


"Lawrence Garvin" wrote in message

> "Yuri Den" wrote in message
>
>
>>>> Hello,
>>>> I need to create a query that will return a sequence of numbers,
>>>> something
>>>> like this:
>>>> 1
>>>> 2
>>>> 3
>>>> ...
>>>> 99
>>>> 100
>
>
>>> declare @i int
>>> declare @maxvalue int
>>>
>>> set @i = 1
>>> set @maxvalue = 100
>>>
>>> while @i <= @maxvalue
>>> begin
>>> select @i
>>> set @i = @i + 1
>>> end
>
>
>> Thanks Lawrence, but that is not what I need.
>> I need single query Select statement. On Oracle it looks like this:
>
>> SELECT LEVEL FROM DUAL
>> CONNECT BY LEVEL <= 100
>
> Yeah.. well, this ain't Oracle, and you got an answer befitting your
> question.
>
> Your query won't provide anything unless there's a table populated with
> data.
>
> Now, if you'd like to provide *additional* constraints to your question...
> Like, maybe, the data is already in a table and you're trying to retreive
> data from the table???
>
> Then maybe something as basic as
> SELECT <column> FROM <table> WHERE <column> <= 100 ORDER BY <column>
>
> But then... if we're asking questions this simple,
> your better source for help is probably a book named something like
> "Teach Yourself T-SQL in Seven Days".
>
> Do you have a real *problem* to solve, or do you just not know anything
> about T-SQL?
>
>
> --
> Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
> Principal/CTO, Onsite Technology Solutions, Houston, Texas
>
 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Lawrence Garvin

External


Since: Oct 16, 2008
Posts: 16



(Msg. 6) Posted: Wed Nov 19, 2008 7:15 pm
Post subject: Re: SQL that generates a sequence [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Yuri Den" wrote in message


> Lawrence, I love your answer! What an elegant solution Smile
> SELECT <column> FROM <table> WHERE <column> <= 100 ORDER BY <column>

<shaking head> I'm glad the solution answered your question. </shaking head>

> In case if someone else encountered with similar problem, here is link to
> solution:
> http://www.projectdmx.com:80/tsql/tblnumbers.aspx

Actually, I think this is the link to the *problem*.

The page at projectdmx.com describes how to *populate* a table with a set of
ordered values.

This solution (and question) describes how to extract a specified set of
values from that table, which I presume the author of the article at
projectdmx.com considered elementary enough not to require explicit
description.

--
Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
Principal/CTO, Onsite Technology Solutions, Houston, Texas
 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Mario

External


Since: Jul 30, 2008
Posts: 3



(Msg. 7) Posted: Mon Feb 09, 2009 12:23 pm
Post subject: Re: SQL that generates a sequence [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Lawrence,

I have no idea why you are shaking your head. Common Table Expressions are
exactly what Yuri was looking for. You may need a few more MS certifications
to figure it out.

"Lawrence Garvin" wrote:

> "Yuri Den" wrote in message
>
>
> > Lawrence, I love your answer! What an elegant solution Smile
> > SELECT <column> FROM <table> WHERE <column> <= 100 ORDER BY <column>
>
> <shaking head> I'm glad the solution answered your question. </shaking head>
>
> > In case if someone else encountered with similar problem, here is link to
> > solution:
> > http://www.projectdmx.com:80/tsql/tblnumbers.aspx
>
> Actually, I think this is the link to the *problem*.
>
> The page at projectdmx.com describes how to *populate* a table with a set of
> ordered values.
>
> This solution (and question) describes how to extract a specified set of
> values from that table, which I presume the author of the article at
> projectdmx.com considered elementary enough not to require explicit
> description.
>
> --
> Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
> Principal/CTO, Onsite Technology Solutions, Houston, Texas
>
>
 >> Stay informed about: SQL that generates a sequence 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
index on a view - Hello, I have a table (TAB) and A View with alias (VIEW) Table cod varchar 3 descr carchar 60 my view cod alias COd1 descr alias DES Now i need a index on view with key COD1 I can't create it. Can..

Creating an alias - I have an alias that can get very long because it maintains a information of where it came from. Is there a way to alias an alias? My first thought was: Declare @T1 varchar(128) Set T1 = 'MyAlias' .... Inner Join Table1 as @T1 This of course does no...

Formatting numeric fields in select-clause - This is propably a very simple question, but I can“t seem to find the answer to it in the documentation. I want to format a numeric field so the result is right justified and zero-filled. ex select 1 will give the result 01 How do I manage this..

Simple Query problem - Sample table as follows Order ID Stock Code Status --------- ------- ------- 203 STK1 3 203 STK2 2 203 STK4 3 204 STK1 3 204 STK5 3 205 ..

query assistance -return most recent date - I have a table that has two fields, pkg_num, which is a number, and del_date_time, which is a date-time. The table can contain duplicate pkg_num values, as long as the del_date_time values are different for any given number. I need a query that will...
   Database Help (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]