MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 24th, 2012, 03:30 AM
Reshaw Reshaw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 4 Reshaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 6 sec
Reputation Power: 0
Probably basic SQL problem

Morning everyone

First of all, apologies if this is a very simple question. I am not very familiar with SQL, I have cannibalised a few queries generated by MS SQL (created via Excel) and reached an impass for something I am trying to achieve, hence the cry for help here.

I am attempting to create a self updating performance spreadsheet for my sales team.

We use a transport planning system called Manpack and I can use MS Query to interrogate this system and pull back any data I want. My reps sign up new accounts and they are given an account name internally and I can construct an SQL query that looks for all the transactions for those named accounts in the current year.

Currently this SQL statement looks like this:
SELECT ANON01_HAJobFile.JobNumber, ANON01_HAJobFile.Account, ANON01_HAJobFile.Volume, ANON01_HAJobFile.Quantity, ANON01_HAJobFile.Value1, ANON01_HAJobFile.DelDate, ANON01_HAJobFile.JobCancelled
FROM DBA.ANON01_HAJobFile ANON01_HAJobFile
WHERE (ANON01_HAJobFile.JobCancelled='N') AND (ANON01_HAJobFile.Account In ('C01','CAR','COC','DEB','HAR','HOL','INT','KAC','RDM','UKC','RDM','DOB','VER')) AND (ANON01_HAJobFile.DelDate Between {d '2012-01-01'} And {d '2012-12-31'})
ORDER BY ANON01_HAJobFile.DelDate

Referring particularily to the bit:- WHERE Job is not cancelled and WHERE job is one of (list of accounts)

Hold that thought a moment please...




Now, we have another system (Sage Act!) which is a prospecting tool, I can also interrogate that and retrieve any info I need from there (and do). One of the things that I can get from Act! easily is a list of Account names for a given Rep in the form of a table. When a rep signs up a new customer, Act! is updated and the table will show the new accounts at the bottom of it.

The code for this looks like:-
SELECT TBL_CONTACT.CUST_AccountCode_015058247, TBL_CONTACT.CUST_Salesperson_053027311
FROM SalesCombined.dbo.TBL_CONTACT TBL_CONTACT
WHERE (TBL_CONTACT.CUST_AccountCode_015058247 Is Not Null) AND (TBL_CONTACT.CUST_Salesperson_053027311='Bryan Surname')
ORDER BY TBL_CONTACT.CUST_AccountCode_015058247



What I need to do is dynamically create the above SQL statement which retrieves all the customer account codes for that salesman from Act! and insert them into the SQL statement above The In list.

I have attempted to use the [] and ? operators so that excel then asks me where to look for the parameter but it doesn't appear to like me adding a range (as opposed to a single cell) and also I need the range to be the length of the table returned which increases over time.

Currently I manually update the Query to include any new accounts but this is time consuming and if I am not here, the reps are not able to do this themselves.

Is it possible to nest the Act! Query within the Manpack one?

I would appreciate any thoughts on this problem you may have
thanks in advance
Rob

Reply With Quote
  #2  
Old July 24th, 2012, 03:39 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,376 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 35 m 25 sec
Reputation Power: 4140
Quote:
Originally Posted by Reshaw
Is it possible to nest the Act! Query within the Manpack one?
don't know, but you can test it...
Code:
SELECT ANON01_HAJobFile.JobNumber
     , ANON01_HAJobFile.Account
     , ANON01_HAJobFile.Volume
     , ANON01_HAJobFile.Quantity
     , ANON01_HAJobFile.Value1
     , ANON01_HAJobFile.DelDate
     , ANON01_HAJobFile.JobCancelled
  FROM DBA.ANON01_HAJobFile ANON01_HAJobFile
 WHERE ANON01_HAJobFile.JobCancelled = 'N'
   AND ANON01_HAJobFile.Account In 
       ( SELECT TBL_CONTACT.CUST_AccountCode_015058247
           FROM SalesCombined.dbo.TBL_CONTACT TBL_CONTACT
          WHERE TBL_CONTACT.CUST_AccountCode_015058247 Is Not Null
            AND TBL_CONTACT.CUST_Salesperson_053027311 = 'Bryan Surname' )
   AND ANON01_HAJobFile.DelDate 
       BETWEEN {d '2012-01-01'} 
           AND {d '2012-12-31'}
ORDER 
    BY ANON01_HAJobFile.DelDate
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old July 24th, 2012, 09:59 AM
Reshaw Reshaw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 4 Reshaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 6 sec
Reputation Power: 0
Many thanks for your prompt reply

I have entered this in as you have it and get the error message
Table 'TBL_CONTACT' not found.

Any ideas?

Reply With Quote
  #4  
Old July 24th, 2012, 10:38 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,376 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 35 m 25 sec
Reputation Power: 4140
Quote:
Originally Posted by Reshaw
Any ideas?
well, i got that from you, didn't i

maybe change this --
Code:
SalesCombined.dbo.TBL_CONTACT
to this --
Code:
dbo.SalesCombined.TBL_CONTACT

Reply With Quote
  #5  
Old July 24th, 2012, 10:52 AM
Reshaw Reshaw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 4 Reshaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 6 sec
Reputation Power: 0
Yeah you did, sorry. I originally copied the code from the connection properties dialogue within Excel, so both sections of code were working as a standalone queries.

I tried swapping the dbo to the front but get error message:
User ID 'Salescombined' does not exist.




Quote:
Originally Posted by r937
well, i got that from you, didn't i

maybe change this --
Code:
SalesCombined.dbo.TBL_CONTACT
to this --
Code:
dbo.SalesCombined.TBL_CONTACT

Reply With Quote
  #6  
Old July 24th, 2012, 11:13 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,376 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 35 m 25 sec
Reputation Power: 4140
Quote:
Originally Posted by Reshaw
I tried swapping the dbo to the front but get error message:
User ID 'Salescombined' does not exist.
well, i'm sorry, i don't really know what your tables are called

but i'm pretty sure 'Salescombined' isn't a User ID

perhaps ms query doesn't allow subqueries?

Reply With Quote
  #7  
Old July 24th, 2012, 11:26 AM
Reshaw Reshaw is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 4 Reshaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 6 sec
Reputation Power: 0
That's what I'm starting to think, there's references all over the web that seem to suggest it is very possible with SQL in general, but it seems that the Select function only works when its is the first line of the code and any subsequent select's are seemingly ignored and that it presumes you are referencing tables in the same database, which I'm not.

Thanks for your help all the same
Rob

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Probably basic SQL problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap