473,805 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1798
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.d e> wrote in message
news:41******** @maser.urz.unib as.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.d e> wrote in message
news:41******** @maser.urz.unib as.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.d e> wrote in message
news:41******** @maser.urz.unib as.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
10240
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 View Query: Select Sq from ( Select substr(to_date(End_Date,"DD-MON-YYYY"),4), End_Date, Rank() Over (Partition by substr(to_date(End_Date,"DD-MON-YYYY"),4) Order by End_Date) As Sq
17
14080
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 query that executed quite quickly in our dev environment was painfully slow in production. I analyzed the the plan on the production server (it looked good), and then tried quite a few tips that I'd gleaned from reading newsgroups. Nothing worked....
17
5033
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 cust_no, ded_type_cd, chk_no)
2
8543
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 example of what I'm trying to do is below: update (tbl_ind_mananas LEFT JOIN (select count(*) as count, (dubicacion || zona || manzana) as cod_manzana from tbl_censo_poblacion_1993 group by dubicacion, zona, manzana) tbl1 on relacion = cod_manzana) as...
4
2259
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 Definitions Differ" dialog box. Anybody know anything about this? I can live this with I guess, however it was sure
10
3287
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 wouldn't work (nothing changed): UPDATE tblManuals SET tblManuals.PARTNUM = Trim(); Would someone please tell me how to do an update query that will trim the spaces?
5
4706
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 the record that is selected in the list box? The data updates right, but I can't get the update query to do anything but update all of the records. Thanks, Andrew
4
11344
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 AddressDescription of Entity 456 = AddressDescription of Entity_ID 123 Address1 of Entity 456 = Address1 of Entity_ID 123 City of Entity 456 = City of Entity_ID 123
12
1632
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 know how to change the query to accept an ' whilst keeping the data true.
16
3526
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 renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.