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 2008 Forums
 Transact-SQL (2008)
 Associated StoredProcedure

Author  Topic 

vijay1234
Starting Member

48 Posts

Posted - 2014-09-18 : 02:17:20
Hi friends,

I have a requirement as follows

I have a table with only one column ID (PrimaryKey).

It has 1,2,3,4,5,6 recrds.

So i would like to create a SP with one input parameter so that if i pass the parameter '1'..then the output should result as 123456

Similarly if i pass '2', then result as 23456

......

if i pass '6' then result should be only 6.

So i would like to know the TSQL query to create this scenario

Thanks,
Vijay

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-18 : 03:03:11
[code]
declare @result varchar(100)
select @result = isnull(@result, '') + CONVERT(VARCHAR(10), ID)
from a_table
where ID >= @input
order by ID
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vijay1234
Starting Member

48 Posts

Posted - 2014-09-18 : 03:16:23
Thanks Friend.

How ever when i'm passing input parameter '3'. The result is nothing but the sum of 3+4+5+6 = 18.

But i just want the ID's to be displayed.

like 3 (input) ----> Result : 3 4 5 6

But not the Sum operation (+).

Hope i'm clear

Thanks,
Vijay
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-18 : 07:01:13
edited the query


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -