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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how can i select names between stu06 to stu10

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-10-23 : 02:18:06
Student info table

stuid Name

stu01 a
stu02 b
stu03 c
stu04 d
stu05 e
stu06 f
stu07 g
stu08 h
stu09 i
stu10 j
stu11 k

how can i select names between

stu06 to stu10

can u tell me the query

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 02:24:19
[code]SELECT *
FROM
(SELECT ROW_NUMBER() OVER(ORDER BY REPLACE(stuid,'stu','')*1) AS Seq,*
FROM StudentInfo
)t
WHERE Seq BETWEEN REPLACE(@start,'stu','')*1 AND REPLACE(@end,'stu','')*1[/code]

pass vales of @start and @end as stu06 and stu10
Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2008-10-23 : 02:29:13
Thanks visakh

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 02:33:43
quote:
Originally posted by kamii47

Thanks visakh

Kamran Shahid
Sr. Software Engineer(MCSD.Net,MCPD.net)
www.netprosys.com



cheers
Go to Top of Page

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-10-23 : 03:13:25
try this

DECLARE @T TABLE (stuid VARCHAR(10), Name VARCHAR(10))

INSERT INTO @T
SELECT 'stu01', 'a' UNION ALL
SELECT 'stu02', 'b' UNION ALL
SELECT 'stu03', 'c' UNION ALL
SELECT 'stu04', 'd' UNION ALL
SELECT 'stu05', 'e' UNION ALL
SELECT 'stu06', 'f' UNION ALL
SELECT 'stu07', 'g' UNION ALL
SELECT 'stu08', 'h' UNION ALL
SELECT 'stu09', 'i' UNION ALL
SELECT 'stu10', 'j' UNION ALL
SELECT 'stu11', 'k'

SELECT * FROM @T
WHERE CONVERT(INT, SUBSTRING(stuid, 4, LEN(stuid))) BETWEEN 6 AND 10


"There is only one difference between a dream and an aim. A dream requires soundless sleep to see, whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-23 : 05:01:13
Implicit conversion



SELECT * FROM @T
WHERE SUBSTRING(stuid, 4, LEN(stuid)) BETWEEN 6 AND 10

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -