Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Fetching values under condition Expand / Collapse
Author
Message
Posted Saturday, September 08, 2012 3:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 08, 2013 4:05 AM
Points: 10, Visits: 57
Hi to all I have a Query which is fix like

SELECT StudentId,EnrolmentId,SessionId,SchoolId, Name, ClassGroupId, ClassId, ClassName FROM ViewStudentTable WHERE IsBlock = 0 and sessionid=11 and schoolid=1 and classid=2

I am searching student under session 11 schoolid 1 and classid 2

Output is fine

But now People searching student under session 11 and in schoolid=1

I don't want to change query i wants that output should come with the same query
Post #1356351
Posted Saturday, September 08, 2012 5:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 21, 2013 7:07 AM
Points: 24, Visits: 100
Once you prefer different outputs, obviously you need to change the filtering. But, i don't know what is the problem of changing the query..

Regards,
Karthik.
SQL Developer.
Post #1356361
Posted Sunday, September 09, 2012 1:16 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945, Visits: 2,782
Where is the DDL?

You have several classic errors. Read the ISO-11179 rules for data element names. We do not use “view” or “table” is a table name; you name it for what is s by its nature, not by its implementation. SQL does not use bit flags; that was Assembly Language in the 1950's.

Here is a guess, made without any help, as to a corrected DDL:

SELECT student_id, enrollment_id, session_id,
school_id, school_name,
class_group, class_id, class_name
FROM Student_Enrollment
WHERE session_id = 11
AND class_status <> 'blocked'
AND school_id = 1
AND class_id = 2;

[quote
I am searching student under (session_id = 11 AND school_id = 1 AND class_id = 2).
[/quote]

No, there was no search condition with session_id in it. I had to add it.


But now People searching student with (session = 11 AND school_id = 1). I do not want to change query. but I want different output


That makes no sense, even after I fixed the English. Write a new query; it is easy.


Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1356503
Posted Sunday, September 09, 2012 10:55 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 4:51 PM
Points: 32,923, Visits: 26,811
goldyabk1 (9/8/2012)
Hi to all I have a Query which is fix like

SELECT StudentId,EnrolmentId,SessionId,SchoolId, Name, ClassGroupId, ClassId, ClassName FROM ViewStudentTable WHERE IsBlock = 0 and sessionid=11 and schoolid=1 and classid=2

I am searching student under session 11 schoolid 1 and classid 2

Output is fine

But now People searching student under session 11 and in schoolid=1

I don't want to change query i wants that output should come with the same query

Create a stored procedure that contains the parameters you want to search for as variables.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1356554
Posted Monday, September 10, 2012 6:17 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, February 14, 2013 12:43 AM
Points: 26, Visits: 92
If you use stored procedure still you need to change the query. So, it is better to change the query directly. without changing the query you can't change the output.
Post #1356684
Posted Tuesday, September 11, 2012 3:45 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 08, 2013 4:05 AM
Points: 10, Visits: 57
Thanks
Post #1357243
Posted Tuesday, September 11, 2012 3:45 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 08, 2013 4:05 AM
Points: 10, Visits: 57
Thanks I got it
Post #1357244
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse