If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > update difficult

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-24-11, 09:36
mhmdsw mhmdsw is offline
Registered User
 
Join Date: Dec 2011
Posts: 4
update difficult

HI
I am some difficult on updating my rows on my databases in sql server 2005 , i am searching but i am not yet found .
if someone know a function or script who help to update : on updating i want to add 1 on each rows
egs : 1 3 CCh4 after update 11 31 CCh41
66 99 VBj6 after update 661 991 VBj61
thanks
Reply With Quote
  #2 (permalink)  
Old 12-24-11, 13:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
could you please script out your table definition, i.e. column names and datatypes
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-24-11, 13:14
mhmdsw mhmdsw is offline
Registered User
 
Join Date: Dec 2011
Posts: 4
there is my table definition

there is my table definition :
table name : note(mat(numeric),cod(varchar),ref(varchar))
Reply With Quote
  #4 (permalink)  
Old 12-24-11, 13:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
UPDATE TABLE [note]
   SET mat = mat * 10 + 1
     , cod = cod + '1'
     , ref = ref + '1'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 12-24-11, 13:38
mhmdsw mhmdsw is offline
Registered User
 
Join Date: Dec 2011
Posts: 4
update

no you don't understand me , i want to update on adding to last position
on field the element 1 and no increasing 1
Reply With Quote
  #6 (permalink)  
Old 12-24-11, 13:51
PracticalProgram PracticalProgram is offline
Registered User
 
Join Date: Sep 2001
Location: Chicago, Illinois, USA
Posts: 551
mhmdsw,

Test-out r937's suggested solution.

I think you will find that it does exactly what you want.
__________________
Ken

Maverick Software Design

(847) 864-3600 x2
Reply With Quote
  #7 (permalink)  
Old 12-24-11, 14:00
mhmdsw mhmdsw is offline
Registered User
 
Join Date: Dec 2011
Posts: 4
update

just adding 1 for each rows
egs : if i two rows :
12 tt1 bby after update 121 tt11 bby1
6 vv6 nnh after update 61 vv61 nnh1

just add the element on last position to the field
Reply With Quote
  #8 (permalink)  
Old 12-24-11, 17:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by mhmdsw View Post
just add the element on last position to the field
try my update statement, please
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 12-25-11, 00:59
Elmozamil Elmozamil is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
try it

Quote:
Originally Posted by r937 View Post
Code:
UPDATE TABLE [note]
   SET mat = mat * 10 + 1
     , cod = cod + '1'
     , ref = ref + '1'
IF you means 1 become 11 and asd become asd1 and qwe become qwe1
the posted solution will solve your problem, first he manipulate the integer number by add place for your new number 1 = 1 * 10 + 1 = 11 right?
and cod = co + '1' (+) is a concatenation operator so asd = asd + '1' = asd1
try it.
Reply With Quote
  #10 (permalink)  
Old 12-25-11, 01:00
Elmozamil Elmozamil is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
try it

Quote:
Originally Posted by r937 View Post
Code:
UPDATE TABLE [note]
   SET mat = mat * 10 + 1
     , cod = cod + '1'
     , ref = ref + '1'
IF you means 1 become 11 and asd become asd1 and qwe become qwe1
the posted solution will solve your problem, first he manipulate the integer number by add place for your new number 1 = 1 * 10 + 1 = 11 right?
and cod = co + '1' (+) is a concatenation operator so asd = asd + '1' = asd1
try it.


Elmozamil

Last edited by Pat Phelan; 12-27-11 at 18:12.
Reply With Quote
  #11 (permalink)  
Old 12-27-11, 01:43
yvesds yvesds is offline
Registered User
 
Join Date: Apr 2007
Location: Antwerp
Posts: 2
Exclamation

Try also the SQL2005 documentation :

1) Learn more about string (char, varchar, ...) concatenation
+ (String Concatenation) (Transact-SQL)
2) Learn more about arithmetic operator :
* (Multiply) (Transact-SQL)
Multiplying by 10 in the decimal world is just as multiply by 2 (decimal) or 10 (binary) in the binary world : just shift all digits 1 position left and put the 0 in the most right open position. After that you add 1 to the numeric value and the 0 in most right position will become a 1.

Just what u want, or not ?
if not give us an example that not match !!
Reply With Quote
Reply

Tags
1 3 cch4 after update

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On