mjburgard
asked on
updating spreadsheet from sql
I have a spreadsheet that successfully queries an sql database to give us a set of numbers. What I would like to do is have this query automatically fill in the next row in the spreadsheet each time it is run. Currently we are copying the numbers from the sheet that is linked to the database to the next sheet. The auto-fill would help save a lot of time.
Thanks
Thanks
>a spreadsheet that successfully queries an sql database
How is the spreadsheet set up to query the database?
For example does it use an external connection, is it populated via a vba macro/sub that uses a recordset which is dumped to the spreadsheet, or some other method?
Why is there a need to copy numbers the next sheet?
Can't the sheet be designed to refer directly to the first sheet?
Or is older data over-written each time?
Rob
How is the spreadsheet set up to query the database?
For example does it use an external connection, is it populated via a vba macro/sub that uses a recordset which is dumped to the spreadsheet, or some other method?
Why is there a need to copy numbers the next sheet?
Can't the sheet be designed to refer directly to the first sheet?
Or is older data over-written each time?
Rob
ASKER
The spreadsheet uses an external connection to query the database -
When the query runs, due to the nature of the data that we are accessing, it overwrites the old data every time.
When the query runs, due to the nature of the data that we are accessing, it overwrites the old data every time.
Set NOCOUNT ON
declare @curr int
declare @cstatus int
declare @cnotin int
DECLARE @cepp int
DECLARE @cproduction INT
DECLARE @cdone INT
set @curr= (select min(jobn) from OpenJob where jobStatus in (0,2) and jobN > 0)
SET @cnotin = 0
SET @cepp = 0
SET @cproduction = 0
SET @cdone = 0
WHILE @curr <= (SELECT MAX(jobN) FROM openJob WHERE jobStatus IN (0,2))
BEGIN
IF EXISTS(SELECT jobn FROM openjob WHERE jobn=@curr AND jobStatus IN (0,2))
BEGIN
SELECT @cstatus=StatusCoden FROM statuscode where statuscoden = (select statuscode from JobStatus1 where jobn = @curr and transactionN = (select max(transactionN) from jobStatus1 where jobn=@curr))
if @cstatus IS NULL set @cstatus = ''
IF @cstatus BETWEEN 35100 AND 35108 SET @cnotin = @cnotin + 1
ELSE
IF @cstatus BETWEEN 35109 AND 35254 SET @cepp = @cepp + 1
ELSE
IF @cstatus BETWEEN 35255 AND 78100 SET @cproduction = @cproduction + 1
ELSE
IF @cstatus >= 78101 SET @cdone = @cdone + 1
END
set @curr = @curr + 1
END
SELECT @cnotin AS 'Not In', @cepp AS 'EPP', @cproduction AS 'Production', @cdone AS 'Done';
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I haven't been able to try this out yet, it is on the list for this week - hopefully very soon.
I've requested that this question be deleted for the following reason:
Not enough information to confirm an answer.
Not enough information to confirm an answer.
ASKER
I modified this and fixed a couple of items that didn't work at first, but i works now.
Is this 'next row' something that the Stored Procedure can do, before it returns the set that is displayed in Excel?
Stored Procedures are executed read-only, meaning you can't edit it in Excel and expect the source data to update. Tables and views yes, SP's no.