Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have got a query that i want to use in a dataset for producing rldc reports in asp.net. The query is
SQL
select schoolname, schoolid, count(studentid) as studenttotals,age,sex from student where left(studentid,4) = 2006

. The query generates correct results. The studentid starts with a year hence in this query i want all students with an id starting with year 2006. Now my challenge is on where left(studentid,4) = 2006, how can i make a parameter so that i can enter any year of my choice lets say i want those whose id start with 2007;2008; etc. I want the parameter to be entered through dropdownlist during report generation.
Posted
Updated 2-Sep-13 23:13pm
v2
Comments
[no name] 2-Sep-13 20:09pm    
"how can i make a parameter", okay and? Did you try anything at all? Did you do any research on parameterized queries?
syed shanu 2-Sep-13 22:01pm    
Create your SP(Stored procedure) In SP you can write your same select query and add parameter to the SP.in your frond end call the SP and pass the parameter for ex

create procedure [dbo].[USP_School_Details Select]
@Years varchar(10);
AS
BEGIN

schoolname, schoolid, count(studentid) as studenttotals,age,sex from student where left(studentid,4) = @Years

END
exec USP_School_Details Select '2007'
Herman<T>.Instance 3-Sep-13 5:14am    
Set as answer so I can give you a good rating
Herman<T>.Instance 3-Sep-13 5:14am    
How can the query give a correct result when no Group By is used?

1 solution

SQL
Create your SP(Stored procedure) In SP you can write your same select query and add parameter to the SP.in your frond end call the SP and pass the parameter for ex

create procedure [dbo].[USP_School_Details Select]
    @Years  varchar(10);
AS
BEGIN

schoolname, schoolid, count(studentid) as studenttotals,age,sex from student where left(studentid,4) = @Years



END
exec  USP_School_Details Select '2007'
 
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