Solved

SQL 2005 error in SQL Query

Posted on 2011-03-15
1
285 Views
Last Modified: 2012-05-11
I am getting the following syntax error and not seeing the root of the issue. Any assistance is appreciated.

Msg 156, Level 15, State 1, Line 28
Incorrect syntax near the keyword 'SET'.
SET NOCOUNT ON

IF NOT EXISTS(SELECT 1 FROM information_schema.TABLES WHERE table_name = 'cusHealthHomesHealthyKidsDiags') 
CREATE TABLE [dbo].[cusHealthHomesHealthyKidsDiags](
		[DiagnosisId][INT] NULL,
		[DiagnosisCode][VARCHAR](10) NULL,
		[CategoryId][VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]


IF NOT EXISTS(SELECT 1 FROM information_schema.TABLES WHERE table_name = 'cusHealthHomesHealthyKidsCategories')
CREATE TABLE [dbo].[cusHealthHomesHealthyKidsCategories](
		[CategoryName][VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
		[CategoryId][VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL 
) ON [PRIMARY] 

INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'ALLERGY','ALG' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'ALG') 
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'ASTHMA','AST' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'AST') 
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'BITES','BTE' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'BTE')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'FOREIGN BODY','FOB' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'FOB')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'INSECT','INS' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'INS')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'LEAD','LED' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'LED')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'SKIN','SKN' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'SKN')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'TINEA','TIN' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'TIN')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'UPPER RESP','URP' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'URP')
END

SET NOCOUNT OFF 

IF( 1 = 1)
BEGIN
SELECT 
	Code, 
	Description
FROM 
	Diagnosis dx
	LEFT OUTER JOIN cusHealthHomesHealthyKidsDiags HKDX ON dx.DiagnosisId = HKDX.DiagnosisId
	LEFT OUTER JOIN cusHealthHomesHealthyKidsCategories HKCAT ON HKDX.CategoryId = HKCAT.CategoryId
END
ELSE
BEGIN

DECLARE @ASSIGNEDCAT VARCHAR(50)
SET @ASSIGNEDCAT = NULL

DECLARE @STATUS varchar(10)
IF(1=2)
	SET @STATUS = 'New '
ELSE
	SET @STATUS = ' '

SELECT 
	Code, 
	Description,
	Category = @STATUS + NULL
FROM
	Diagnosis
WHERE
	DiagnosisId IN(NULL)
END

Open in new window

0
Comment
Question by:Jeff S
1 Comment
 
LVL 9

Accepted Solution

by:
Roman Gherman earned 500 total points
ID: 35138989
Hi,
you need to remove the END statement before SET NOCOUNT OFF

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question