mjburgard
asked on
SQL Difficulty importing to Excel
I am trying to bring data into Excel with some SQL code. The code works fine and when I work with it in Microsoft Query it returns the data (while saying the Query cannot be represented graphically). However, when I return the data to Excel all I get is "Query from [Database]" and none of the data. Is there a way to get the data I need into a spreadsheet?
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';
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 @production = @production + 1
ELSE
IF @cstatus >= 78101 SET @done = @done + 1
Perhaps something got chopped out of your example, like a SELECT-statement.
You could put all the logic and data-gathering into a stored-procedure, and get MS-Excel to run that stored-procedure to produce a result-set.
You could put all the logic and data-gathering into a stored-procedure, and get MS-Excel to run that stored-procedure to produce a result-set.
ASKER
The code accidentally included extra lines. Everything after line 38 shouldn't be there. (Is it possible to edit the question and fix this? I cannot figure out how to.)
The SELECT statement on line 38 returns the data I was talking about.
The SELECT statement on line 38 returns the data I was talking about.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your code does not return any data, it just sets some local variables.