D
Danny
I am working with Office XP, SQL Server 2000 with the latest service packs.
I have a sp that uses a temporary table to gather records to be displayed in
a result table.
The ‘SET NOCOUNT ON’ statement is at the top of the procedure and it works
perfectly in Query Analyzer.
Can anyone crack this nut?
Code…
CREATE PROCEDURE spQualityCheck
(@JobID int, @ProductionOnly bit = 0) AS
SET NOCOUNT ON
DECLARE @SpecDescription nvarchar(255)
DECLARE @TableName nvarchar(50)
DECLARE @FieldName nvarchar(50)
DECLARE @Spec nvarchar(255)
DECLARE @SQL nvarchar(1000)
DECLARE @JobString as nvarchar(15)
--Create a temporary table to hold the results of the spec checks.
CREATE TABLE #Temp (Roll int, [Spec Name] nvarchar(255), Spec nvarchar(255),
Measurement nvarchar(10))
--Check if there are rolls to test
IF NOT EXISTS(SELECT * FROM tblRolls WHERE(JobId = @JobID))
GOTO BAILOUT
--Loop through each of the specifications
SET @JobString = CONVERT(nvarchar(15), @JobID)
DECLARE CSR CURSOR LOCAL
FOR
SELECT SpecDescription, TableName, FieldName, Spec
FROM tblJobSpecifications
WHERE JobID = @JobID AND
(AlertInProduction = 1 OR AlertInProduction = @ProductionOnly)
OPEN CSR
FETCH NEXT FROM CSR INTO @SpecDescription,
@TableName,
@FieldName,
@Spec
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL = 'INSERT INTO #Temp
SELECT RollNumber as Roll, ''' +
@SpecDescription + ''' as [Spec Name], ''' +
@Spec + ''' as Spec, Left(CAST([' +
@FieldName + '] AS nvarchar), 10)
as Measurement
FROM ' + @TableName +
' WHERE JobID = ' +
@JobString + ' AND NOT ([' +
@FieldName + '] ' +
@Spec + ') AND RollStatus = ''G'' AND
(RollDisposition = ''S'' OR RollDisposition = ''H'')'
PRINT @SQL
EXEC (@SQL)
--Move to the next record
FETCH NEXT FROM CSR INTO @SpecDescription, @TableName,
@FieldName, @Spec
END
CLOSE CSR
DEALLOCATE CSR
BAILOUT:
SELECT * FROM #Temp
GO
I have a sp that uses a temporary table to gather records to be displayed in
a result table.
The ‘SET NOCOUNT ON’ statement is at the top of the procedure and it works
perfectly in Query Analyzer.
Can anyone crack this nut?
Code…
CREATE PROCEDURE spQualityCheck
(@JobID int, @ProductionOnly bit = 0) AS
SET NOCOUNT ON
DECLARE @SpecDescription nvarchar(255)
DECLARE @TableName nvarchar(50)
DECLARE @FieldName nvarchar(50)
DECLARE @Spec nvarchar(255)
DECLARE @SQL nvarchar(1000)
DECLARE @JobString as nvarchar(15)
--Create a temporary table to hold the results of the spec checks.
CREATE TABLE #Temp (Roll int, [Spec Name] nvarchar(255), Spec nvarchar(255),
Measurement nvarchar(10))
--Check if there are rolls to test
IF NOT EXISTS(SELECT * FROM tblRolls WHERE(JobId = @JobID))
GOTO BAILOUT
--Loop through each of the specifications
SET @JobString = CONVERT(nvarchar(15), @JobID)
DECLARE CSR CURSOR LOCAL
FOR
SELECT SpecDescription, TableName, FieldName, Spec
FROM tblJobSpecifications
WHERE JobID = @JobID AND
(AlertInProduction = 1 OR AlertInProduction = @ProductionOnly)
OPEN CSR
FETCH NEXT FROM CSR INTO @SpecDescription,
@TableName,
@FieldName,
@Spec
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL = 'INSERT INTO #Temp
SELECT RollNumber as Roll, ''' +
@SpecDescription + ''' as [Spec Name], ''' +
@Spec + ''' as Spec, Left(CAST([' +
@FieldName + '] AS nvarchar), 10)
as Measurement
FROM ' + @TableName +
' WHERE JobID = ' +
@JobString + ' AND NOT ([' +
@FieldName + '] ' +
@Spec + ') AND RollStatus = ''G'' AND
(RollDisposition = ''S'' OR RollDisposition = ''H'')'
PRINT @SQL
EXEC (@SQL)
--Move to the next record
FETCH NEXT FROM CSR INTO @SpecDescription, @TableName,
@FieldName, @Spec
END
CLOSE CSR
DEALLOCATE CSR
BAILOUT:
SELECT * FROM #Temp
GO