0

I am getting an error in this query like incorrect syntax near distinct statement

DECLARE  @CNT INT
SELECT @CNT= DISTINCT ISNULL(Employee.id,0)
FROM Employee 
WHERE EMPLOYEE.NAME='KIRAN'

is there anything wrong in syntax

SELECT  DISTINCT ISNULL(Employee.id,0)
FROM Employee 
WHERE EMPLOYEE.NAME='KIRAN'

this statements works fine

thanks prince

2 Answers 2

1

Something like this maybe ..

DECLARE  @CNT INT
SET @CNT = (SELECT DISTINCT ISNULL(Employee.id,0)
FROM Employee 
WHERE EMPLOYEE.NAME='KIRAN')
Sign up to request clarification or add additional context in comments.

2 Comments

than you have a problem .. but that wasn't the question
the Query returns same value even for multiple row values
0

1.use must write distinct before @CNT variable
2.select only first row because @cnt not table variable it is variable which type is int

DECLARE  @CNT INT
SELECT top 1 @CNT= ISNULL(Employee.id,0)
FROM Employee 
WHERE EMPLOYEE.NAME='KIRAN'

you can test it simply

declare @CNT INT

SELECT top 1 @CNT= ISNULL(Employee.id,0)
FROM Employee 
WHERE EMPLOYEE.NAME='KIRAN'

select @CNT 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.