Code compiles but I get alot of errors for line "SELECT Substring ..." because chemicalId, chemicalTitle, chemicalDescription, chemicalCountry, chemicalState, chemicalCity, etc. gets the following errors:
Invalid column name 'chemicalId'
Invalid column name 'chemicalTitle'
Invalid column name 'chemicalDescription,'
Invalid column name 'chemicalCountry'
Invalid column name 'chemicalState'
Invalid column name 'chemicalCity,'
etc
I am trying to get values to print out values for @Chunk1, @Chunk2, and @Chunk3 which are part from the TEXT chemicalsInfo column of a Temp Table.
--------------------------------------------------------
CREATE TABLE #TempChemicalsChunk
(
ID int IDENTITY,
chemicalsInfo TEXT
)
DECLARE EmailCursor CURSOR FOR
SELECT ae.emailAlertId, ae.emailAlertState, ae.emailAlertCountry, ae.emailAlertEmail, ae.chemicalIndustryId, ae.chemicalTypeId, ae.chemicalAskingPrice
FROM emailalert ae, users u
WHERE (... lots more code ...)
OPEN EmailCursor
FETCH NEXT FROM EmailCursor
INTO @EmailAlertId, @emailAlertState, @emailAlertCountry, @emailAlertEmail, @chemicalIndustryId, @chemicalTypeId, @chemicalAskingPrice
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #TempChemicals (chemicalId, chemicalIndustryDescription, chemicalTypeDescription, chemicalIndustryId2, chemicalTypeId2, chemicalTitle, chemicalCity, chemicalState, chemicalCountry, chemicalAskingPrice2, chemicalSalesRevenue, chemicalNetProfit, chemicalDescription)
SELECT b.chemicalId, cI.chemicalIndustryDescription, bT.chemicalTypeDescription, c.chemicalIndustryId, c.chemicalTypeId, c.chemicalTitle, c.chemicalCity, c.chemicalState, c.chemicalCountry, c.chemicalAskingPrice, c.chemicalSalesRevenue, c.chemicalNetProfit, c.chemicalDescription
FROM chemical c, chemicalIndustry cI, chemicalType cT
WHERE c.chemicalIndustryId = cI.chemicalIndustryId
AND c.chemicalTypeId = cT.chemicalTypeId
AND c.chemicalIndustryId = @chemicalIndustryId
AND c.chemicalTypeId = @chemicalTypeId
AND c.chemicalCountry = @emailAlertCountry
AND c.chemicalState = IsNull(@emailAlertState, chemicalState)
ORDER BY c.chemicalTitle ASC
IF @@ROWCOUNT > 0
BEGIN
INSERT INTO #TempChemicalsChunk (chemicalsInfo)
SELECT Substring('<A href=" + CAST(chemicalId AS varchar) + '" target="NEW">' + dbo.PROPER(chemicalTITLE) + '</A><BR>' + dbo.SentenceCase(LEFT(chemicalDescription, 80)) + '...<BR>' + REPLACE((chemicalCountry + ' > ' + chemicalState + ' > ' + dbo.PROPER(chemicalCity) + '<BR>'), '> >', '>') + REPLACE('Asking Price: ' + chemicalAskingPrice2 + ' * Revenue: $' + LEFT(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalSalesRevenue, 0)), 1), LEN(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalSalesRevenue, 0)), 1))-3) + ' * Profit: $' + LEFT(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalNetProfit, 0)), 1), LEN(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalNetProfit, 0)), 1))-3) + ' *<BR><BR>', '$0', 'Call/Email'), 1, 8000)
SELECT @Chunk1 = Substring(chemicalsInfo, 1, 8000) FROM #TempChemicalsChunk
SELECT @Chunk1 = Substring(chemicalsInfo, 8001, 8000) FROM #TempChemicalsChunk
SELECT @Chunk1 = Substring(chemicalsInfo, 16001, 8000) FROM #TempChemicalsChunk
print '@Chunk1: ' + @Chunk1
print '@Chunk2: ' + @Chunk2
print '@Chunk3: ' + @Chunk3
Truncate table #TempChemicals
FETCH NEXT FROM EmailCursor
INTO @EmailAlertId, @emailAlertState, @emailAlertCountry, @emailAlertEmail, @chemicalIndustryId, @chemicalTypeId, @chemicalAskingPrice
END
END
CLOSE EmailCursor
DEALLOCATE EmailCursor
END
Invalid column name 'chemicalId'
Invalid column name 'chemicalTitle'
Invalid column name 'chemicalDescription,'
Invalid column name 'chemicalCountry'
Invalid column name 'chemicalState'
Invalid column name 'chemicalCity,'
etc
I am trying to get values to print out values for @Chunk1, @Chunk2, and @Chunk3 which are part from the TEXT chemicalsInfo column of a Temp Table.
--------------------------------------------------------
CREATE TABLE #TempChemicalsChunk
(
ID int IDENTITY,
chemicalsInfo TEXT
)
DECLARE EmailCursor CURSOR FOR
SELECT ae.emailAlertId, ae.emailAlertState, ae.emailAlertCountry, ae.emailAlertEmail, ae.chemicalIndustryId, ae.chemicalTypeId, ae.chemicalAskingPrice
FROM emailalert ae, users u
WHERE (... lots more code ...)
OPEN EmailCursor
FETCH NEXT FROM EmailCursor
INTO @EmailAlertId, @emailAlertState, @emailAlertCountry, @emailAlertEmail, @chemicalIndustryId, @chemicalTypeId, @chemicalAskingPrice
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #TempChemicals (chemicalId, chemicalIndustryDescription, chemicalTypeDescription, chemicalIndustryId2, chemicalTypeId2, chemicalTitle, chemicalCity, chemicalState, chemicalCountry, chemicalAskingPrice2, chemicalSalesRevenue, chemicalNetProfit, chemicalDescription)
SELECT b.chemicalId, cI.chemicalIndustryDescription, bT.chemicalTypeDescription, c.chemicalIndustryId, c.chemicalTypeId, c.chemicalTitle, c.chemicalCity, c.chemicalState, c.chemicalCountry, c.chemicalAskingPrice, c.chemicalSalesRevenue, c.chemicalNetProfit, c.chemicalDescription
FROM chemical c, chemicalIndustry cI, chemicalType cT
WHERE c.chemicalIndustryId = cI.chemicalIndustryId
AND c.chemicalTypeId = cT.chemicalTypeId
AND c.chemicalIndustryId = @chemicalIndustryId
AND c.chemicalTypeId = @chemicalTypeId
AND c.chemicalCountry = @emailAlertCountry
AND c.chemicalState = IsNull(@emailAlertState, chemicalState)
ORDER BY c.chemicalTitle ASC
IF @@ROWCOUNT > 0
BEGIN
INSERT INTO #TempChemicalsChunk (chemicalsInfo)
SELECT Substring('<A href=" + CAST(chemicalId AS varchar) + '" target="NEW">' + dbo.PROPER(chemicalTITLE) + '</A><BR>' + dbo.SentenceCase(LEFT(chemicalDescription, 80)) + '...<BR>' + REPLACE((chemicalCountry + ' > ' + chemicalState + ' > ' + dbo.PROPER(chemicalCity) + '<BR>'), '> >', '>') + REPLACE('Asking Price: ' + chemicalAskingPrice2 + ' * Revenue: $' + LEFT(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalSalesRevenue, 0)), 1), LEN(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalSalesRevenue, 0)), 1))-3) + ' * Profit: $' + LEFT(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalNetProfit, 0)), 1), LEN(CONVERT(VARCHAR, CONVERT(MONEY, ISNULL(chemicalNetProfit, 0)), 1))-3) + ' *<BR><BR>', '$0', 'Call/Email'), 1, 8000)
SELECT @Chunk1 = Substring(chemicalsInfo, 1, 8000) FROM #TempChemicalsChunk
SELECT @Chunk1 = Substring(chemicalsInfo, 8001, 8000) FROM #TempChemicalsChunk
SELECT @Chunk1 = Substring(chemicalsInfo, 16001, 8000) FROM #TempChemicalsChunk
print '@Chunk1: ' + @Chunk1
print '@Chunk2: ' + @Chunk2
print '@Chunk3: ' + @Chunk3
Truncate table #TempChemicals
FETCH NEXT FROM EmailCursor
INTO @EmailAlertId, @emailAlertState, @emailAlertCountry, @emailAlertEmail, @chemicalIndustryId, @chemicalTypeId, @chemicalAskingPrice
END
END
CLOSE EmailCursor
DEALLOCATE EmailCursor
END