Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL UPDATE using a variable

Status
Not open for further replies.

albertp

Programmer
May 27, 2004
2
US
I would like to update a field in an Access table using the SQL
update command.
The following syntax will work if I want to update a specific value
in a field.

UPDATE CustomerTable
SET City = Atlanta
Where Zipcode = 30303

Could anyone tell me the correct syntax to set city = a variable like

txtCityName = Baltimore
UPDATE CustomerTable
SET City = txtCityName
Where Zipcode = 30303

Thanks in advance to anyone who can help
 

You should look at the declare statement. Here is an example from BOL...

USE pubs
DECLARE @find varchar(30)
SET @find = 'Ring%'
SELECT au_lname, au_fname, phone
FROM authors
WHERE au_lname LIKE @find
 
By the way, this forum is for Microsoft SQL Server. Since you are looking for help with Access, I suggest posting in an Access forum.

All SQL is not created equal. There are differences between the languages. SQL Server uses Transact-SQL and I believe Access uses Jet-SQL.

-SQLBill



SELECT 'forum' CASE [SQL TYPE]
WHEN 'MySQL' THEN 'forum436'
WHEN 'Access' THEN 'forum700', 'forum701', 'forum702', 'forum703', 'forum704', 'forum181'
WHEN 'ORACLE' THEN 'forum185' 'forum186', 'forum759'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top