Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Distinct syntax

Author  Topic 

eem_2055
Yak Posting Veteran

69 Posts

Posted - 2008-01-28 : 05:15:42
Hi guys,

Could you please help me. I have an an error message of this upon running this: "Incorrect syntax near the keyword 'distinct'.

'OldIdNo' = distinct (C.Id1 + C.Id2 + C.Id3 + C.Id4)


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-28 : 05:23:44
If you tell me your business rule for this, I might be able to help.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-01-28 : 05:24:43
you cannot use distinct (C.Id1 + C.Id2 + C.Id3 + C.Id4). You can use
Select distinct C.Id1 , C.Id2 , C.Id3 , C.Id4 from yourtable.

EDIT: This is incorrect. correct replies are given in posts below.


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 05:28:52
quote:
Originally posted by eem_2055

Hi guys,

Could you please help me. I have an an error message of this upon running this: "Incorrect syntax near the keyword 'distinct'.

'OldIdNo' = distinct (C.Id1 + C.Id2 + C.Id3 + C.Id4)





Can you post the full query?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-28 : 05:29:23
Yes you can.
DECLARE	@Sample TABLE (a VARCHAR(2), b VARCHAR(2), c VARCHAR(2), d VARCHAR(2))

INSERT @Sample
SELECT 'A', 'B', 'C', 'D' UNION ALL
SELECT 'AB', 'CD', '', ''

SELECT DISTINCT (a + b + c + d)
FROM @Sample



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 05:31:18
quote:
Originally posted by sunil

you cannot use distinct (C.Id1 + C.Id2 + C.Id3 + C.Id4). You can use
Select distinct C.Id1 , C.Id2 , C.Id3 , C.Id4 from yourtable.






select distinct (t.a+t.b) as sums from
(
select 34 as a , 16 as b union all
select 12 as a , 22 as b union all
select 34 as a , 16 as b
)as t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 05:33:54


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-01-28 : 05:37:18
sorry eem_2055 for posting what i have come to know is incorrect.But, I read or heard it from some one.Thanks Peso and Madhi for the correction.
Go to Top of Page
   

- Advertisement -