|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Ok,
This should be simple but it must be to early..... I'm trying to add a 0 to some columns in my database So if my ProductID = 12345 I want to make it = 012345 and I want to do this for the hole productID column Thanks for the help! |
|
#2
|
||||
|
||||
|
if productid is a character datatype, then use this:
Code:
update products set productid = '0' + productid but if productid is numeric, then the only way you'll ever see the leading zero is if you use '0' + cast(productid as varchar) in every SELECT statement Last edited by r937 : October 26th, 2004 at 10:45 AM. |
|
#3
|
|||
|
|||
|
Server: Msg 195, Level 15, State 10, Line 2
'concat' is not a recognized function name. the field is a varchar |
|
#4
|
|||
|
|||
|
yep that last one work TY ... that was simple *smack head*
|
|
#5
|
|||
|
|||
|
Server: Msg 2601, Level 14, State 3, Line 1
Cannot insert duplicate key row in object 't_productID' with unique index 'idx_productID'. The statement has been terminated. So I need to do if excits to drop it or just plan out skip that row, and i will drop it later |
|
#6
|
||||
|
||||
|
Code:
update products as x set productid = '0' + productid where not exists ( select '0' + productid from products where productid = x.productid ) or something like that |
|
#7
|
|||
|
|||
|
I tried something simalur to that but got an invalid expression on the 'AS' x
|
|
#8
|
||||
|
||||
|
yeah, sorry, you have to use FROM syntax in order to use an alias
please try this: Code:
update products
set productid = '0' + t1.productid
from products t1
left outer
join products t2
on t1.productid = '0' + t2.productid
where t2.productid is null
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Add 0 to excisting number |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|