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 8, 2012 3:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 8, 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 8, 2012 5:42 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, August 4, 2014 5:46 AM
Points: 33, Visits: 156
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 9, 2012 1:16 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 10:54 AM
Points: 1,945, Visits: 2,897
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 9, 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: Today @ 8:33 AM
Points: 36,958, Visits: 31,465
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
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: Tuesday, June 17, 2014 7:45 AM
Points: 27, Visits: 120
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 8, 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 8, 2013 4:05 AM
Points: 10, Visits: 57
Thanks I got it
Post #1357244
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse