473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Update Query question.

This is a little frustrating, because it should be easy.

I have an application that has been converted to SQL Server 2000 from MS
Access 97. New data is loaded each week and one of my old queries will no
longer work to assist with formatting the data.

I have a Phone Number field that is Varchar 10

The numbers have imported without the leading zero.

In access I used to run

UPDATE Main
SET Main.PhoneNr = '0' & Main.PhoneNr

This does not work in SQL Server.
Any suggestions?
Jul 20 '05 #1
4 1779
Scott Berry wrote:
This is a little frustrating, because it should be easy.

I have an application that has been converted to SQL Server 2000 from MS
Access 97. New data is loaded each week and one of my old queries will no
longer work to assist with formatting the data.

I have a Phone Number field that is Varchar 10

The numbers have imported without the leading zero.

In access I used to run

UPDATE Main
SET Main.PhoneNr = '0' & Main.PhoneNr

This does not work in SQL Server.
Any suggestions?


string concatenation is done with the plus-sign in SQL-Server.
so

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

should work.
Other possible problems:
where PhoneNr not like '0*'
becomes
where PhoneNr not like '0%'
NULL-values might also be handled different then you are used to.
hth,
Tobias
Jul 20 '05 #2
Tobias,

Thanks. I tried the query with '+' sign

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

but it set all my field values to '0' without the existing 9 characters.

Any other thoughts?
Scott
"Tobias Marquart" <to******@gmx.de> wrote in message
news:41********@maser.urz.unibas.ch...
Scott Berry wrote:
This is a little frustrating, because it should be easy.

I have an application that has been converted to SQL Server 2000 from MS
Access 97. New data is loaded each week and one of my old queries will no
longer work to assist with formatting the data.

I have a Phone Number field that is Varchar 10

The numbers have imported without the leading zero.

In access I used to run

UPDATE Main
SET Main.PhoneNr = '0' & Main.PhoneNr

This does not work in SQL Server.
Any suggestions?


string concatenation is done with the plus-sign in SQL-Server.
so

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

should work.
Other possible problems:
where PhoneNr not like '0*'
becomes
where PhoneNr not like '0%'
NULL-values might also be handled different then you are used to.
hth,
Tobias

Jul 20 '05 #3
Hi Scott,

what client are you using to execute the query?
As it does not do what you normally would expect,
I can only guess what is wrong.

If I run the query as described in query analyzer it gives the result
you want to have:
(sample code provided)

create table Main (cId int identity(1,1) primary key, cName
varchar(100), cPhoneNr varchar(10))
insert into Main (cName, cPhoneNr) values('Test A','123456781')
insert into Main (cName, cPhoneNr) values('Test B','123456782')
insert into Main (cName, cPhoneNr) values('Test C','123456783')
insert into Main (cName, cPhoneNr) values('Test D','123456784')
select * from Main
update Main set Main.cPhoneNr = '0' + Main.cPhoneNr
select * from Main
Tobias

Scott Berry wrote:
Tobias,

Thanks. I tried the query with '+' sign

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

but it set all my field values to '0' without the existing 9 characters.

Any other thoughts?
Scott
"Tobias Marquart" <to******@gmx.de> wrote in message
news:41********@maser.urz.unibas.ch...
Scott Berry wrote:
This is a little frustrating, because it should be easy.

I have an application that has been converted to SQL Server 2000 from MS
Access 97. New data is loaded each week and one of my old queries will no
longer work to assist with formatting the data.

I have a Phone Number field that is Varchar 10

The numbers have imported without the leading zero.

In access I used to run

UPDATE Main
SET Main.PhoneNr = '0' & Main.PhoneNr

This does not work in SQL Server.
Any suggestions?


string concatenation is done with the plus-sign in SQL-Server.
so

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

should work.
Other possible problems:
where PhoneNr not like '0*'
becomes
where PhoneNr not like '0%'
NULL-values might also be handled different then you are used to.
hth,
Tobias


Jul 20 '05 #4

"Scott Berry" <sb@bp.net.au> wrote in message
news:X3******************@news-server.bigpond.net.au...
Tobias,

Thanks. I tried the query with '+' sign

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

but it set all my field values to '0' without the existing 9 characters.

Any other thoughts?
Scott
"Tobias Marquart" <to******@gmx.de> wrote in message
news:41********@maser.urz.unibas.ch...
Scott Berry wrote:
This is a little frustrating, because it should be easy.

I have an application that has been converted to SQL Server 2000 from MS Access 97. New data is loaded each week and one of my old queries will no longer work to assist with formatting the data.

I have a Phone Number field that is Varchar 10

The numbers have imported without the leading zero.

In access I used to run

UPDATE Main
SET Main.PhoneNr = '0' & Main.PhoneNr

This does not work in SQL Server.
Any suggestions?


string concatenation is done with the plus-sign in SQL-Server.
so

UPDATE Main
SET Main.PhoneNr = '0' + Main.PhoneNr

should work.
Other possible problems:
where PhoneNr not like '0*'
becomes
where PhoneNr not like '0%'
NULL-values might also be handled different then you are used to.
hth,
Tobias


You said the numbers had imported without the leading zero - are you sure
that they weren't imported as a numeric value? If they had been you could
try,
SET Main.PhoneNr = '0' + CAST (Main.PhoneNr AS VARCHAR (9) )

Sorry if I haven't read your question correctly - 9:15 is far too early in
the morning ;-)

Rowland.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
17
by: Felix | last post by:
Dear Sql Server experts: First off, I am no sql server expert :) A few months ago I put a database into a production environment. Recently, It was brought to my attention that a particular...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
4
by: dp | last post by:
After looking and looking, it appears that Access ADPs graphic query designer won't display: update customer set = . from customer, where customer. = .; It comes up with the "Query...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
5
by: Andrew | last post by:
I've got a list box that selects a record on a subform, and in that subform are a few text fiels and a button that runs an update query. How do I have the update query button run and only update...
4
by: deko | last post by:
I'm trying to update the address record of an existing record in my mdb with values from another existing record in the same table. In pseudo code it might look like this: UPDATE tblAddress SET...
12
by: si_owen | last post by:
Hi all, I have a SQL query that worked fine in my project until it came to testing. I found that the NvarChar fields I have wont accept the use of an ' My code and query is here does anyone...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.