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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update query

Status
Not open for further replies.

RosieGp

Programmer
Jun 23, 2009
83
0
0
US
I have the follwoing query that is updating the data in table SupplierTable1
Code:
UPDATE SupplierTable1 
SET    TodayDate = '#DATEFORMAT(Now(), "mm/dd/yyyy")#',
       Suppliermail = '#form.Supplieremail#',    
       SupplierStreet = '#form.SupplierStreet#',
       SupplierCity = '#form.SupplierCity#', 
       SupplierState = '#session.SupplierState#',    
       SupplierMiles = '#session.SupplierMiles#',
       SupplierPhone = '#session.SupplierPhone#',    
       SupplierMailBox = '#session.SupplierMailBox#'
WHERE SupplierID=#form.SupplierID#
Now I want the above query to update data only if SupplierID exists in VendorTable and the orderDate is not null.

I have another UPDATE query
Code:
UPDATE SupplierTable1 
SET    TodayDate = '#DATEFORMAT(Now(), "mm/dd/yyyy")#',
       Suppliermail = '#session.Supplieremail#',    
       SupplierStreet = '#session.SupplierStreet#',
       SupplierCity = '#session.SupplierCity#',
       SupplierState = '#form.SupplierState#',    
       SupplierMiles = '#form.SupplierMiles#',
       SupplierPhone = '#form.SupplierPhone#',    
       SupplierMailBox = '#form.SupplierMailBox#'
WHERE SupplierID=#form.SupplierID#
Now I want the above query to update data only if SupplierID exists in VendorTable and the orderDate is null.
CAN I COMBINE BOTH Queries.
 
Usually, this sort of thing is accomplished using an exists query, like this:

Code:
If Exists(Select 1 From Vendor where VendorId = '#Whatever#' orderDate is not null)
  Begin
    -- Your update query here
  End

You can also use 'Not Exists' like this:

Code:
If [!]Not[/!] Exists(Select 1 From Vendor where VendorId = '#Whatever#' orderDate is not null)
  Begin
    -- Your update query here
  End


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I see you are using the # symbol as a wildcard. Is this for Access? If so, I'd suggest posting in an Access forum on this site. This is for Microsoft SQL Server and while some of the SQL code is the same, there is enough different that anything we suggest for you might not work.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
It's ColdFusion. The OP is asking much of the same questions in the Coldfusion forum.

-----------
With business clients like mine, you'd be better off herding cats.
 
Thanks Philhege for letting me know that...I've never used ColdFusion so the #'s threw me off.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top