Advertisement

04.25.2008 at 10:43AM PDT, ID: 23354287
[x]
Attachment Details

T-SQL: Return Numbers Between Low and High

Asked by mlprosper in SQL Query Syntax, MS SQL Server, SQL Server 2005

Tags: SQL

I have 2 numbers, a low and high - I need to return the numbers in between the low and high in a SELECT statement in 2 different formats.

Example:
Low: 3
High: 12

First format (each number is its own row)

SchoolID       Grade
5                    3
5                    4
5                    5
5                    6
5                    7
5                    8
5                    9
5                    10
5                    11
5                    12


Second format (1 row, 2 columns)
SchoolID             GradeLevels
5                         3,4,5,6,7,8,9,10,11,12

I will always know what the low and high are beforehand.  The second format I would preferably like to encapsulate into a function so that I can pass the low and high to the function and be able to return the comma delimited list into an existing query.Start Free Trial
[+][-]04.25.2008 at 11:09AM PDT, ID: 21441936

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 11:10AM PDT, ID: 21441948

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 11:21AM PDT, ID: 21442029

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 11:28AM PDT, ID: 21442096

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 12:01PM PDT, ID: 21442377

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 12:24PM PDT, ID: 21442534

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 12:42PM PDT, ID: 21442661

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL Server, SQL Server 2005
Tags: SQL
Sign Up Now!
Solution Provided By: mark_wills
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.25.2008 at 12:44PM PDT, ID: 21442679

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 12:45PM PDT, ID: 21442683

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628