Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to bring variable values in where clause?
See link below in fiddles example. I want the code1 to be unique.

What I have tried:

Schema:
SQL
CREATE TABLE test (
  id INT,
  code1 varchar(5),
  cityname varchar(24),
  clue varchar(255)
);
INSERT INTO test (id, code1, cityname, clue) VALUES (1, 01, 'edison', 4567);
insert into test (id, code1, cityname, clue)
values(2, 01, 'highland park', 8765);
INSERT INTO test (id, code1, cityname, clue) VALUES (3, 02, 'franklin', 7865);


Query:
SQL
SELECT code1, cityname, count(*) as 'nofoftrsnsfers', sum(clue) FROM test
where code1 = 01
group by code1, cityname;
Posted
Updated 8-Jul-22 19:36pm
v2
Comments
0x01AA 8-Jul-22 14:24pm    
try again to phrase a question

1 solution

No, you cannot put the column name as a parameter.

You can, however, build the SQL query statement dynamically and EXECute that instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900