[SQL Server] How do I query dates |
Posted: 18 Apr 2013 02:43 AM PDT Seems simple enuf? So I have a datetime field in a db which happens to be 04/10/2013I do a select * from orderswherecreate_date like '%/10/%'returns nothing. So clear not that simple. I have a URL with either a date &date=11/11/2011 or d=a&m=2&y=2012I need to do w where (day in date_created=url.d) or some such. Better still where date_created=url.dateThanks for your patience with something that has to be SO simple ... did google it and looked up a couple of reference books! |
Posted: 18 Apr 2013 03:01 AM PDT Table with Values[code]CREATE TABLE InitialData(recno int PRIMARY KEY, Dept Varchar(30), entry_name Varchar(50), entry varchar(500), orgID int)INSERT INTO InitialData Values(1, 'Marketing', 'Timesservedstartdate', '8/6/2012 12:00:00 AM', 1234),(2, 'Sales', 'Timesservedstartdate', '8/6/2012 12:00:00 AM', 1234),(3, 'Development', 'Reporting', 'Somevalue', 1234),(4, 'HumanResources', 'Reporting', '1', 1234),(5, 'Support', 'Reporting', '1', 1234);[/code]Trying to test the condition that i developed...i want to compare all the rows with the entry value '1'. Any values other than 1 should be equal to 0 is the condition. NOTE: entry is a varchar column[code] IF (SELECT COALESCE((SELECT dI.[entry] FROM dbo.InitialData AS dI WITH(NOLOCK) WHERE dI.Dept = 'Reporting' AND dI.entry_name = 'PledgeRequireBatch' AND dI.orgID = 1234 AND dI.[entry] <> 1), 0)) = 1 BEGIN Select * from InitialData END ELSE Select TOP 1 * FROM InitialData[/code]I am getting the else statement result always but that is not what i want1 Marketing Timesservedstartdate 8/6/2012 12:00:00 AM 1234 |
Posted: 17 Apr 2013 10:08 PM PDT Hi,I need a help.i have 5 tables defined below:-these tables are used to record all data pertaining to emails.Emarketing_email_history : message_stub,acct_id,....Survey_email_history : message_stub,acct_id,....Event_email_history : message_stub,acct_id,....this record all data pertaining to email bounce.Email_history_log : message_stub....this is acct specific data.Account: acct_id,acct_namei want to get the count of all acct's that have bounced emails.my query below:-select top 500 a.acct_id, a.acct_num, a.acct_company, count(a.acct_id) from email_history_log ehl (nolock)join email_history ehe (nolock) on ehe.message_stub = ehl.message_stubjoin survey_email_history ehs (nolock) on ehs.message_stub = ehl.message_stubjoin emarketing_email_history ehm (nolock) on ehm.message_stub = ehl.message_stubjoin account a on a.acct_id = ehm.acct_id -----------????where ehl.created_date > (dateadd("day",-7,getdate()))GROUP BY a.acct_id, a.acct_num, a.acct_companyORDER BY count(a.acct_id) DESCbut some how this doesnt retrive records. though when I remove join condition( i e removing 2 joins from join 1 ,2 or 3) I get records.is there any way I can get my result by joining all 3 tables plus account table with event_history_log?PS i dont want union/union allhelp much appritiated.!!:hehe:Thanks! |
Posted: 17 Apr 2013 08:00 PM PDT Hello Masters,Is it possible to know when last backup was restored on specific database ? Is it possible to know if any database has been overwrite ? |
You are subscribed to email updates from SQLServerCentral / SQL Server 2008 / SQL Server Newbies To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment