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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Reserve Word

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-10 : 19:27:32
Vidya writes "Hi...

I am trying to convert some of the sqls from Access to SQL 2000...

I need to know if we can use the reserve word "IN" in the column_name Please let me how to convert this in sql
declare @r_1_id int
Set @r_1_id =1



SELECT DISTINCT
A.pk_R_ID,
----this is giving an error in sql-----------------
(@r_id_1 in (A.pk_r_1,A.pk_r_2,A.pk_r_3)) as id1,
----this is giving an error in sql-----------------
A.pk_r_1,
A.pk_r_2,
A.pk_r_3
From
A
Where
(@r_id_1 in
(A.pk_r_1,
A.pk_r_2,
A.pk_r_3)
)
This works in access where as when I try to "In" in SQL it gives me an error

Any clues --------

Thanks"

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-02-10 : 19:50:58
quote:

SELECT DISTINCT
A.pk_R_ID,
----this is giving an error in sql-----------------
(@r_id_1 in (A.pk_r_1,A.pk_r_2,A.pk_r_3)) as id1,
----this is giving an error in sql-----------------
A.pk_r_1,
A.pk_r_2,
A.pk_r_3
From
A
Where
(@r_id_1 in
(A.pk_r_1,
A.pk_r_2,
A.pk_r_3)
)



I don't quite understand why you want the field id1 when every record returned will have the same value (since it's in the where clause) - but what you want is:

SELECT DISTINCT
A.pk_R_ID,
id1 = case when @r_id_1 in (A.pk_r_1,A.pk_r_2,A.pk_r_3) then 1 else 0 end,
A.pk_r_1,
A.pk_r_2,
A.pk_r_3
From
A

hope that's what you want

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page
   

- Advertisement -