Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, November 22, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Data & Imports Forums - T-SQL & Queries
Forum to discuss general T-SQL questions and help with queries related to SalesLogix data. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to T-SQL & Queries | New ThreadView:  Search:  
 Author  Thread: Need Help With SQL Update Statement
Bailey1
Posts: 57
 
Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Feb 11 9:18 AM
fiogf49gjkf0d

I am trying to update SIC Codes on the Account table with data provided by an outside source on another table. I tried executing the following SQL statement in the SLX Administrator, but I get errors: "Failed to parse SQL"


UPDATE ACCOUNT
SET MODIFYDATE=GETDATE(),
 MODIFYUSER='Admin',
 SICCODE = L.SICCODE 
from ACCOUNT A, LoadTable L
where A.ACCOUNTID = L.ACCOUNTID 



This query works fine in SQL Server Query Analyzer, but I need the changes to be synched down to
the remote databases, so I need to run them in the SLX Admin. I am on SLX ver 7.5.2.  Any suggestions?


 


[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Feb 11 11:59 AM
fiogf49gjkf0d

1. The SLX OLE DB Provider automagically takes care of ModifyData, ModifyUser so need for Setting those fields.


2. SLX OLE DB Provider doesn't like none explicit join updates....fully qualifed selects work just fine.


Try this


UPDATE ACCOUNT
SET  SICCODE =
(SELECT L.SICCODE 
from LoadTable L
where ACCOUNT.ACCOUNTID = L.ACCOUNTID  )


 

[Reply][Quote]
Bailey1
Posts: 57
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 12:03 PM
fiogf49gjkf0d

Thanks RJ, but I just tried it and I got the "Failed to Parse SQL" error. Any other ideas?

[Reply][Quote]
Lane
Posts: 121
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 12:38 PM
fiogf49gjkf0d

drop the modifydate out of it.


the field is managed by the provider and the getdate() function can't pass through sync so will fail.


Test you sql through QueryAnalyzer.exe using a slx provider connection (but be advised if it works, it will be in the sync queue as well, based on the setup)


 

[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 12:54 PM
fiogf49gjkf0d

Quote:
Originally posted by Lane


Test you sql through QueryAnalyzer.exe using a slx provider connection



Is that possible in QA? Been a while since I used it.


A (perhaps safer) way of testing such statements is using the 'Test' function in the Tools / Execute SQL part of Administrator, which executes the statement as part of a transaction and then rolls it back (after verifying whether it worked).

[Reply][Quote]
John Gundrum
Posts: 632
Top 10 forum poster: 632 posts
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 1:48 PM
fiogf49gjkf0d

I second using the Execute SQL function in Administrator.  It is a much safer way of testing SQL scripts.

[Reply][Quote]
Bailey1
Posts: 57
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 1:49 PM
fiogf49gjkf0d

I used the 'TEST' function in Tools/Execute SQL, and I didn't get the 'Fail to Parse Sql' error, but it also tried to update every account on the account table.  It does not update ONLY the accounts where the accountid matches the accountid on the load table, but ALL accounts, so this will not work.  


This is the SQL I tested:


 UPDATE ACCOUNT
SET  SICCODE =
(SELECT I.SICCODE 
from INFOUSA_LOAD I
where ACCOUNT.ACCOUNTID = I.ACCOUNTID  )

[Reply][Quote]
John Gundrum
Posts: 632
Top 10 forum poster: 632 posts
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 1:55 PM
fiogf49gjkf0d

That update will update all acounts because there is no where statement for the UPDATE statement.  You need to move the where to outside the subquery.  In addition to that I think you need to refine the sub-query to include a different where statement condition unless there is a SLX accountid field in the INFOUSA_LOAD table.  The basic SQL will look like this

UPDATE ACCOUNT
SET  SICCODE =
(SELECT I.SICCODE 
from INFOUSA_LOAD I WHERE {condition} = {condition})
WHERE ACCOUNT.ACCOUNTID = I.ACCOUNTID

[Reply][Quote]
John Gundrum
Posts: 632
Top 10 forum poster: 632 posts
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 2:00 PM
fiogf49gjkf0d

Be aware that the sub-query can cause a failure if it returns more than one record.  Verify the where conditions for the sub-query so it will only return one valid record.  There is a way to gaurentee only one record is return but I wouldn't advise using this method because if more than record is returns indicates there is a data validity issue.

[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 07 Feb 11 2:00 PM
fiogf49gjkf0d

Quote:
Originally posted by Bailey1


I used the 'TEST' function in Tools/Execute SQL, and I didn't get the 'Fail to Parse Sql' error, but it also tried to update every account on the account table.  It does not update ONLY the accounts where the accountid matches the accountid on the load table, but ALL accounts, so this will not work.  


This is the SQL I tested:


 UPDATE ACCOUNT
SET  SICCODE =
(SELECT I.SICCODE 
from INFOUSA_LOAD I
where ACCOUNT.ACCOUNTID = I.ACCOUNTID  )



That's because you have no WHERE clause in your outer SQL. Try this (untested):


 


UPDATE ACCOUNT
SET  SICCODE =
(SELECT I.SICCODE 
from INFOUSA_LOAD I
where ACCOUNT.ACCOUNTID = I.ACCOUNTID  )
WHERE ACCOUNT.ACCOUNTID in (Select i2.AccountID from INFOUSA_LOAD I2)

 


 

[Reply][Quote]
Bailey1
Posts: 57
 
Re: Need Help With SQL Update StatementYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Feb 11 8:52 AM
fiogf49gjkf0d

Thanks Phil - I think I got it to work!

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/22/2024 10:08:24 AM