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
 Need help

Author  Topic 

mani_1234
Starting Member

24 Posts

Posted - 2012-09-10 : 00:07:54
hi all ..

i have sample data like this
create table #tem
(
a char ,
b char(10)
)

insert #tem
select '1','000000' union all
select '2','000000' union all

select '3','000000' union all
select '4','000000'

INPUT
a b
1 000000
2 000000
4 000000
OUTPUT
and my requiremnt is
a b
1 100000
2 010000
4 000100

i hope u all understood the requirment... i want to replace the digit of b column from 0 to 1 on the basis of value of a .
for e.g if a =1 and b =000000 in input then output must be 100000 ( i.e 1 places in first digit ... how can i achieve ths ....help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-10 : 00:28:00
[code]
SELECT a,STUFF(b,a,1,'1')
FROM Table
[/code]

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

Go to Top of Page

mani_1234
Starting Member

24 Posts

Posted - 2012-09-10 : 01:04:46
Argument data type char is invalid for argument 2 of stuff function.
showing ths error becz a is char type not integer type
Go to Top of Page

mani_1234
Starting Member

24 Posts

Posted - 2012-09-10 : 01:05:37
thnx got the answer by using converting function

SELECT a,STUFF(b,convert(int,a),1,'1')
FROM #tem
Go to Top of Page

mani_1234
Starting Member

24 Posts

Posted - 2012-09-10 : 01:45:04
suppose i have one table
a no
a 2
a 1
b 3
b 2

now i want a output in another table e.g final
a output
A 110000
B 011000

how can i implement it...
Go to Top of Page

mani_1234
Starting Member

24 Posts

Posted - 2012-09-10 : 02:19:41
is there any method without using stuff
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-09-10 : 02:35:18
[code]
select a, right(replicate('0', 6) + convert(varchar(6), sum(power(10, 6 - n))), 6)
from table1
group by a
[/code]


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

Go to Top of Page

mani_1234
Starting Member

24 Posts

Posted - 2012-09-10 : 03:21:04
really nice ...thnx
Go to Top of Page
   

- Advertisement -