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

Need help in getting SQL query Expand / Collapse
Author
Message
Posted Saturday, March 22, 2014 10:37 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, March 22, 2014 11:31 PM
Points: 1, Visits: 2
Hi All,

Need your help on getting the sql query for the below data
EMP ID Flag Processing Date
ABC1 yes Current Date
ABC1 No Old Date
DEF1 Yes Current Date
DEF1 No Old Date
GHI1 Yes Old Date
JKL1 yes Current Date
JKL1 No Old Date

i need to select only EMP ID for the above table for which Flag is set to Yes and Processing Date is old Date.

Thank you
Santosh
Post #1553791
Posted Saturday, March 22, 2014 11:52 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 5:11 PM
Points: 35,777, Visits: 32,450
santuraj12 (3/22/2014)
Hi All,

Need your help on getting the sql query for the below data
EMP ID Flag Processing Date
ABC1 yes Current Date
ABC1 No Old Date
DEF1 Yes Current Date
DEF1 No Old Date
GHI1 Yes Old Date
JKL1 yes Current Date
JKL1 No Old Date

i need to select only EMP ID for the above table for which Flag is set to Yes and Processing Date is old Date.

Thank you
Santosh


Just add mostly what you said the a WHERE clause.


--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 #1553795
Posted Monday, March 24, 2014 9:08 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 4:31 PM
Points: 680, Visits: 6,858
Jeff Moden (3/22/2014)
santuraj12 (3/22/2014)
Hi All,

Need your help on getting the sql query for the below data
EMP ID Flag Processing Date
ABC1 yes Current Date
ABC1 No Old Date
DEF1 Yes Current Date
DEF1 No Old Date
GHI1 Yes Old Date
JKL1 yes Current Date
JKL1 No Old Date

i need to select only EMP ID for the above table for which Flag is set to Yes and Processing Date is old Date.

Thank you
Santosh


Just add mostly what you said the a WHERE clause.


And you might have to match the date format for GETDATE() to what is in your table.
But I would question the actual design.
What updates Current Date?
If you wait a day, what happens?
Post #1554084
Posted Wednesday, March 26, 2014 12:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 11:13 PM
Points: 4, Visits: 6
Select Emp_ID from table_Name where Flag='yes' and processing_date='Old Date'
Post #1554789
Posted Wednesday, March 26, 2014 12:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 11:13 PM
Points: 4, Visits: 6
Select Emp_ID from table_Name where Flag='yes' and Processing_Date='Old Date'
Post #1554790
Posted Friday, April 25, 2014 8:29 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:13 AM
Points: 4, Visits: 30


select empid from tablename where flag='yes' and processingdate='old date'
Post #1565117
Posted Wednesday, May 14, 2014 10:08 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 4:45 PM
Points: 1,945, Visits: 3,185
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You are not even close! Temporal data should use ISO-8601 formats; “current date” is a narrative description and not a temporal value. Code should be in Standard SQL as much as possible and not local dialect.

You did not give us what is called the attribute property Think about how useless “emp” is; we need “emp_<something>” to make sense, but what is “emp” by itself? Height? Weight? Name? Id number?

Likewise there is no magical universal “id” in RDBMS. This is especially awful because it violates the Law of Identity. This is freshman logic.

We do not use flags in RDBMS. That was assembly language. We wrote SQL to a “predicate language” instead You detect a status with a logical test on the current state of the database.

The narratives “Current Date” and “Old Date” are relative and are not units of measurement on a calendar.

If you really want to use this non-table, then just turn your narrative into SQL.


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 #1570926
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse