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.
| 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 000000OUTPUTand my requiremnt is a b 1 100000 2 010000 4 000100i 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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 |
 |
|
|
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 |
 |
|
|
mani_1234
Starting Member
24 Posts |
Posted - 2012-09-10 : 01:45:04
|
| suppose i have one table a noa 2a 1 b 3b 2 now i want a output in another table e.g final a output A 110000 B 011000how can i implement it... |
 |
|
|
mani_1234
Starting Member
24 Posts |
Posted - 2012-09-10 : 02:19:41
|
| is there any method without using stuff |
 |
|
|
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 table1group by a[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
mani_1234
Starting Member
24 Posts |
Posted - 2012-09-10 : 03:21:04
|
| really nice ...thnx |
 |
|
|
|
|
|
|
|