SQL Statement To Compare Between Date
Nov 30, 2007
Hi Guys,
I have a table "HOLIDAY" with column "HOLIDAYSTART" and "HOLIDAYEND" in date/time type.
User can apply new holiday on a form with value "STARTDATE" and "ENDDATE",
but how do I check if the new holiday dates already exist in the table??
I looked around and found you can use something similar to following to check for single date,
select * from holiday where ('1-12-2007' >= HOLIDAYSTART) AND ('1-12-2007' <= HOLIDAYEND)
but how would I do it with my situation above with between 2 dates? any help?
Thanks in advance.
View 3 Replies
ADVERTISEMENT
Nov 15, 2007
Hi, I really need this help urgently.
I need to send an email when the dueDate(field name in database) is equal to today's date... I have come out with this code with the help of impathan(jimmy i did not use ur code cos i not very sure sry)... below is the code with no error... but it jus wun send email...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
con1.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "select * from custTransaction where convert(datetime,dueDate,101) = convert(datetime,GetDate(),101)"
'Set the connect the command object should use
cmd.Connection = con1Dim da As New SqlDataAdapter(cmd)Dim ds As New DataSet
da.Fill(ds)
con1.Close()
If Not ds.Tables(0) Is Nothing ThenIf ds.Tables(0).Rows.Count > 0 Then
Dim objEmail As MailMessage = New MailMessage
objEmail.From = New MailAddress("my@email.com.sg")objEmail.To.Add(New MailAddress("my@email.com.sg"))
objEmail.Subject = "Due Date Reaching"objEmail.Body = Session("dueName")
objEmail.Priority = MailPriority.Normal
Dim SmtpMail As New SmtpClient("servername")
SmtpMail.Send(objEmail)
End If
End If
End Sub
Note: I am veri sure that database has the data field dueDate with the value 11/16/2007 smalltimedate(mm/dd/yyyy)
Realli veri urgent Thanks so much for ur'll help
View 8 Replies
View Related
Dec 11, 2007
I need to do the following and am hoping someone can help me out.
I have C#(asp.net app) that will call a stored procedure. The C# will pass in a date to thestored procedure. The date is in the format YY/MM/DD. Once inside of the stored procedure, the datepassed into the stored proc needs to be compared to todays date. Todays date must be determined inthe SQL.
So basically here is my pseudo code for what I am trying to accomplish. Basically I just am afterthe comparison of the two values:
If @BeginDate < TodaysDate
The difficult part is how to obtain the value for "TodaysDate"
Taking into consideration that "TodaysDate" should probably be in the format of YY/MM/DD considering that is how the date it is to be compared with is being passed in.
Can someone please code this out for me in Microsoft SQL. I would be forever grateful.
View 1 Replies
View Related
Sep 21, 2006
HiI am using SQL 2005, VB 2005I am trying to insert a record using parameters using the following code as per MotLey suggestion and it works finestring insertSQL; insertSQL = "INSERT INTO Issue(ProjectID, TypeofEntryID, PriorityID ,Title, Area) VALUES (@ProjectID, @TypeofEntryID, @PriorityID ,@Title, @Area)"; cmdInsert SqlCommand; cmdInsert=new SqlCommand(insertSQL,conn); cmdInsert.Parameters.Add("@ProjectID",SqlDbType.Varchar).Value=ProjectID.Text; My query is how to detail with dates my previous code wasinsertSQL += "convert(datetime,'" + DateTime.Now.ToString("dd/MM/yy") + "',3), '";I tried the code below but the record doesn't save?string date = DateTime.Now.ToString("dd/MM/yy"); insertSQL = "INSERT INTO WorkFlow(IssueID, TaskID, TaskDone, Date ,StaffID) VALUES (@IDIssue, @IDTask, @TaskDone, convert(DateTime,@Date,3),@IDStaff)"; cmdInsert.Parameters.Add("IDIssue", SqlDbType.Int).Value = IDIssue.ToString();cmdInsert.Parameters.Add("IDTask",SqlDbType.Int).Value = IDTask.Text;cmdInsert.Parameters.Add("TaskDone",SqlDbType.VarChar).Value = TaskDoneTxtbox.Text;cmdInsert.Parameters.Add("Date",SqlDbType.DateTime).Value = date;cmdInsert.Parameters.Add("IDStaff",SqlDbType.Int).Value = IDStaff.Text;Could someone point to me in the right direction?Thanks in advance
View 3 Replies
View Related
Jan 26, 2005
Hello,
I have a table called INVENTORY.
The fields in the table are:
inventory_id
warehouse_id
item_id
slot
qty
on_hand_qty
The support tables are the item table and the warehouse table
I am trying to create a report showing the inventory of items of warehouse_id 1 with warehouse_id 2. If there is no inventory for either warehouse then suppress it. That in itself isn't that hard to do, but I would like to put them side by side, and that I'm having a hard time with.
I hope i didn't confuse the question, and any help would be greatly appreciated!
View 1 Replies
View Related
Jun 13, 2008
Hi,
I have a table with 3 columns inside
- record_id (int)
- user_id (varchar)
- login_date (date)
it is a many-to-many relationship table that record login date of users
Now, I want if I want to COUNT the users who login before 31 May 2008, I would use
SELECT COUNT(*)
FROM table1
WHERE login_date < '2008-31-05'
That's works
But the problem is I want to split the result to
- How many people have login in the last 0-5 days (based on the input (31 MAY 2008))
- How many people have login in the last 6-10 days (based on the input (31 MAY 2008))
How do I do that?
Please help
View 5 Replies
View Related
Jun 20, 2008
I have table:ArticleIDSubjectBodyDateThe Date field have data:12.02.200512.02.198912.02.156314.09.134530.12.345I need to show Articles wiich have date today. Example:If today is 12.02.2008 I should show only Date with value 12.02. The results:12.02.2005
12.02.1989
12.02.1563 I try something with DAY, Returns an integer representing the day datepart of the specified date but it's doesn't work.Help :)
View 5 Replies
View Related
Feb 2, 2005
How do you compare date in sql, it is giving me errors,
I want to view all that logged onto my system Today
(*Yes I want to use dyn query for this *)
LastLogin is of type DateTime
SELECT @myStatement = ' SELECT LastLogin, surname
FROM #TEMP WHERE ((LastLogin ='+CONVERT(datetime, @LastLogin)+')
exec(@myStatement)
Thanks in advance
View 4 Replies
View Related
Nov 4, 2005
I want to know how can I write a sql to compare 2 dates which can run in SQL Query Analyzedeclare @date1 datetime, @date2 datetime
set @date1 = '2005-01-22 12:00:05'set @date2 = '2005-01-22 13:05:01'how can I compare whether @date1 = @date2 in terms of (YYYY-MM-DD) only?
View 3 Replies
View Related
Apr 19, 2007
is there a way to have a select statement which compares a value is like ('%a%','%b%','%c%','%d%','%f%','%l%')
so :
select address
from customers
where address like ('%a%','%b%','%c%','%d%','%f%','%l%')
???
View 6 Replies
View Related
Oct 18, 2006
Hello,In my table, I have two columns - ForecastSales and ActualSales. I needto write a query that returns me just one aggregate value (one row andone column). If sum(ActualSales - ForecastSales) is negative, I need toreturn "red." Otherwise, I need to return green.I looked at CASE statement. However, I could not figure out anefficient way to build this query. I would appreciate your help.Thank you in advance for your help.Pradeep
View 3 Replies
View Related
Jul 30, 2007
I'm doing DTS, Here is one of my Sql Query in DTS
Select * From ZT_DailyRpt_Detail Where isNumeric(TenDayDate) = 1 And TenDayDate < Convert(varchar(10),DateAdd(Month,-CAST ((SELECT keepmonth FROM zt_databackup a, zt_biller b WHERE a.companycode = b.companycode AND zt_DailyRpt_Detail.biller_code = b.billercode) AS int),GetDate()),112)
the sub query �SELECT keepmonth FROM zt_databackup a, zt_biller b WHERE a.companycode = b.companycode AND zt_DailyRpt_Detail.biller_code = b.billercode) AS int】will return a value 6 or 12
for the reason, every month have differnet days, ( some have 31 days , some are 30 days ) I don't want to check the day of date , only to compare month
if sub query return "6" and I do DTS on 2007/07/29 , will select date which TenDayDate< 2007/01 not TenDayDate<2007/01/29 ( don't want to check the day of date)
does my query correct? if not can you correct it for me? thank you very much
View 2 Replies
View Related
Aug 2, 2004
I'm stuck trying to compare date values from users selection against a database. I also need to add a condition statement on if the results return no match. How would I do that?
Also, I'm not even sure if my SELECT statement is right. The user will hit a date that will be in format m/d/yyyy and that will be compared to see if it exist in the database. The datebase column "date_created" is default with date/time( 8 ). But when I compare the to together, nothing returns back. The page loads successfully, but no results from the database.
Here is my code:
dim conpubs as sqlconnection
dim cmdSelectAuthors as sqlcommand
dim dtrAuthors As sqlreader
conpubs = New sqlconnection(configurationsettings.appSettings("STD"))
conpubs.open()
cmdSelectAuthors = New sqlcommand("Select * From HotNews WHERE date_created=" & y, conpubs)
dtrAuthors = cmdSelectAuthors.ExecuteReader()
Response.Write("<table><tr><td>")
While dtrAuthors.Read()
Response.Write(dtrAuthors("title") & "<br>")
End While
Response.Write("</td></tr></table>")
dtrAuthors.close()
conPubs.close()
View 1 Replies
View Related
Aug 2, 2000
I want to write a query to retrieve all the items that are
order between 2 dates range, 07/30/2000 to 08/02/2000, any suggestions are
greatly appreciated,
View 4 Replies
View Related
Jan 10, 2006
I have a preexisting database that has dates in the format mm/dd/yyyy but it is set up as varcar. How can I apply numeric operators to it to find how old someone is from todays date? I then need to take that value and populate another column on the same row.
View 1 Replies
View Related
Jan 4, 2006
Hello, I am wondering how to select the max date from a database view containing multiple date fields for a particular record. I am rusty at SQL and can't seem to get started. Here's an example of the data:
PRCL_IDPROJ_STRT_DTORD_DT ...
1242/3/20063/5/2006
5206/3/20068/2/2006
6412/31/2005
1872/14/20063/16/2006
I need to be able to compare the max date for each PRCL_ID record ("where prcl_id="). In the example above, prcl_id 124 has a max date of 3/5/2006, and prcl_id 520 has a max date of 8/2/2006, etc. The results of the SQL query should return the PRCL_ID and the max date.
Example query results:
PRCL_ID ORD_DT
124 3/5/2006
Please let me know if you can help or if I can provide more info.
Thanks,
Alexkav
View 6 Replies
View Related
Aug 2, 2004
I'm stuck trying to compare date values from users selection against a database. I also need to add a condition statement on if the results return no match. How would I do that?
Also, I'm not even sure if my SELECT statement is right. The user will hit a date that will be in format m/d/yyyy and that will be compared to see if it exist in the database. The datebase column "date_created" is default with date/time( 8 ). But when I compare the to together, nothing returns back. The page loads successfully, but no results from the database.
Here is my code:
dim conpubs as sqlconnection
dim cmdSelectAuthors as sqlcommand
dim dtrAuthors As sqlreader
conpubs = New sqlconnection(configurationsettings.appSettings("STD"))
conpubs.open()
cmdSelectAuthors = New sqlcommand("Select * From HotNews WHERE date_created=" & y, conpubs)
dtrAuthors = cmdSelectAuthors.ExecuteReader()
Response.Write("<table><tr><td>")
While dtrAuthors.Read()
Response.Write(dtrAuthors("title") & "<br>")
End While
Response.Write("</td></tr></table>")
dtrAuthors.close()
conPubs.close()
View 1 Replies
View Related
Oct 10, 2005
Hi,
I need to compare 2 periods (start date / end date) in order to find out if the first period overlaps or in included in the second period.
any idea ???
thanks
View 14 Replies
View Related
Sep 25, 2013
From my table:
convert(varchar,Rec.expdate,101) as exp:
01/19/2038
08/12/2013
08/12/2013
I only want record is >= the current date but looks like my syntax is not working right because I got nothing return instead of 01/19/2038.
and convert(varchar,Rec.expdate,101) >=convert(varchar,getdate(),101)
View 3 Replies
View Related
Apr 27, 2015
I compare two table with JOIN statement. Now I would like to update one of them base on result. How it to do?
View 2 Replies
View Related
May 16, 2004
Hi all,
I have encountered a problem that I can't compare the date in SQL Server 2000.
But I know that maybe I have used "datetime" as data type for that field.
My question is that, how can I get ONLY the "date" in stead of "datetime" from the database?
Your attention is appreciated!
Thank you.
Regards,
katszeto
View 8 Replies
View Related
Mar 30, 2015
I need to compare the date column. The date column is 2012-01-22 in this format.
So I need to convert getdate() into this format yyyy-mm-dd.
What is the style number I have to use?
I used the link [URL] but I didn't see this format.
View 5 Replies
View Related
Nov 2, 2003
Hi,
I am using one datetime data type ( name: date_added ) and getdate() as default value. I want to display only those records added today. How I can compare current date with date_added.
Thanks
Manoj
View 1 Replies
View Related
Nov 6, 2007
Right the answer is probably simple but the Internet and books and everything has been no joy to me whatsoever.
I want to split my data stream based on the date. So I want to use a conditional split object to do this.
I entered the following as my case date_created > (DT_DBTIMESTAMP)"01/10/2000"
When I move off the line it stays black so appears to be okay, yet when I run my package it says it is not a boolean result and fails. Can anyone please tell me what I am doing wrong.
Also I cannot filter in the source call due to the sheer amount of work being done on the data before the split.
Thanks in advance for any help
View 5 Replies
View Related
Oct 20, 2015
I need to take all records from table @A where ID = 1. Also i need to process the records with datewise from table @A. Here is the table structure
DECLARE @A TABLE (ID INT, ACCOUNT VARCHAR(10), EFFDT DATE)
INSERT INTO @A VALUES (1,'AAA','2015-10-01')
INSERT INTO @A VALUES (1,'BBB','2015-10-01')
INSERT INTO @A VALUES (1,'CCC','2015-10-01')
INSERT INTO @A VALUES (1,'AAA','2015-10-05')
INSERT INTO @A VALUES (1,'DDD','2015-10-01')
INSERT INTO @A VALUES (2,'AAA','2015-10-02')
INSERT INTO @A VALUES (2,'BBB','2015-10-02')
INSERT INTO @A VALUES (2,'CCC','2015-10-02')
INSERT INTO @A VALUES (2,'DDD','2015-10-02')
[code]...
how to achieve this in SQL query, i cannot use CTE or temp table as i need to use this code in another tool, it has to be single query, can use subquery or join would be better.
View 4 Replies
View Related
Dec 14, 2012
I have a scenario where I need to compare a single DateTime field in a stored procedure against multiple values passed into the proc.So I was thinking I could pass in the DateTime values into the stored procedure with a User Defined Table type ... and then in the stored procedure I would need to run through that table of values and compare against the CreatedWhenUTC value.I could have the following queries for example:
WHERE CreatedWhenUTC <= dateValue1 OR CreatedWhenUTC <= dateValue2 OR CreatedWhenUTC <= dateValue 3
The <= is determined by another operator param passed in. So the query could also be:
WHERE CreatedWhenUTC > dateValue1 OR CreatedWhenUTC > dateValue2 OR CreateWhenUTC > dateValue3 OR CreateWhenUTC > dateValue4
View 3 Replies
View Related
Jul 1, 2015
A vehicle loading confirm after that what time its gated out so i want to take the time duration between finish loading and gate out, find sample table records , i want to take more than 5 hrs difference between finish loading and gate out.
tld_tripno
tld_sno
tld_activitycode
tld_location
tld_actualdate
TLM3004242015
[Code] .....
I want to take the result like thisÂ
Tld_tripno
Finish Loading
Gate Out
Date and Time difference
TLM3004242015
2015-05-11 19:58:00
2015-05-12 08:42:00
12:44:00
View 10 Replies
View Related
Mar 27, 2008
Hi,
I am very new to using SQL. Our department usually uses Brio to query the various databases under our control. However, I have recently come against a problem that prompted me to create a custom SQL query which works well as far as it goes. My problem is looking for specific conditions in billing information I receive monthly. I would like to compare on of the date fields contained in the database with a field in the form of YYYYMM (200710, for October 2007) I have created a custom column generator that forms a date from the YYYYMM. I would like, however, do the translation on the fly and make the comparison during the query. The problem is that query without the date check returns a mass of data, only about 1 percent of which is what I want.
The beginning of the SQL query looks like this:
FROM From.T_Crs_Tran_Dtl WHERE T_Crs_Tran_Dtl.Crs_Bill_Yr_Mo IN ('200710', '200711', '200712') AND ((T_Crs_Tran_Dtl.Crs_Cde IN ('1G', '1V') AND (T_Crs_Tran_Dtl.Dptr_Dte < LastDay(ToDate(Substr ( Crs_Bill_Yr_Mo, 5, 2 )& "/1/"&Substr ( Crs_Bill_Yr_Mo, 1, 4 )))) AND (T_Crs_Tran_Dtl.Prev_Stats_Cde IN (' ', 'TK', 'TL') AND T_Crs_Tran_Dtl.Cur_Stats_Cde IN ('TK', 'TL') AND T_Crs_Tran_Dtl.Std_Tran_Typ_Cde='B') OR (T_Crs_Tran_Dtl.Prev_Stats_Cde='UN' AND T_Crs_Tran_Dtl.Cur_Stats_Cde='XX' AND€¦
It is the €ś(T_Crs_Tran_Dtl.Dptr_Dte < LastDay(ToDate(Substr ( Crs_Bill_Yr_Mo, 5, 2 )& "/1/"&Substr ( Crs_Bill_Yr_Mo, 1, 4 )))) AND€? part of the query that is just plain wrong. The business part of this statement takes the YYYYMM field and turns it into a date which is the last day of YYYYMM.
I hope someone out there can help me with making this comparison.
I appreciate your help.
Bill
View 8 Replies
View Related
Apr 27, 2001
If I used the following syntax, I get 0 rows but I know I have records that were modified a year ago from current date.
c2.lastdate=getdate()-365
What is the syntax I should use to return rows based on the current date?
Any ideas?
Valeria
View 2 Replies
View Related
Jul 20, 2005
Hi,I'm trying to run a select statement that takes includes an if/elseclause. I need to select the 'tran_date' between....if the current month is greater than 10 i.e. after OCT then thetran_date will be between '01-Oct' - plus current year or thetran_date is '01-Oct' plus previous year.and the current dateHere is my script so far:SELECT a.resource_code ASSOCIATE, a.tran_date START_DATE,b.description PROJECT_CODE, sysdateFROM actrans a, acactivity b, dual cWHERE a.resource_type = 'E'AND a.acct_category = 'TIME'and a.activity like '9-WW-357852%'and b.activity = a.activityand tran_date betweenif to_char(sysdate, 'MM') > 10)begina.tran_date = '01-Oct' & to_char(sysdate, 'YY')endelsebegina.tran_date = '01-Oct' & to_char(sysdate, 'YY'- 1))EndORDER BY tran_dateCan anyone help me out with this? I need to run it as a job, but notsure whether I should be using a stored procedure etc..Thanks in advance.George
View 1 Replies
View Related
Sep 6, 2006
I am selecting older legacy data from an AS400 mainframe that we still use. I am fairly new to constructing T-SQL statements so I hope I am doing this correctly. There is a table from the AS400 that has been setup with a field for TMONTH, TDAY, and TYEAR. Instead of having one field for a date, for some reason years ago this was set up this way.
I now have this statement in my SELECT statement and it is not working:
WHERE (CAST(OWNR.TMONTH + '/' + OWNR.TDAY + '/' + OWNR.TYEAR AS DATETIME) >= @startdate)
I am not getting a syntax error, however I am getting "Error Converting data type varchar to numeric. These fields on the AS400 are set up as numeric fields.
What do I need to do differently? Should I use a CONVERT instead and if so, how would I structure that statement.
Thanks for the help
View 3 Replies
View Related
Jan 5, 2004
I'm trying to write a select statement that will show me the total payments, last payment date, and last payment amount for each client. I get results but it is all payments. Can anyone help me with this?
Thank you,
Here is what I have tried:
SELECT dbo.tblClients.Client_ID, Sum(dbo.tblPaymentReceipts.[Amount Paid]) AS SumOfAmtPaid, MAX(dbo.tblPaymentReceipts.[Date]) AS LastPaymentDate, dbo.tblPaymentReceipts.[Amount Paid] INTO #temp_UNPaymentsA
FROM dbo.tblPayments INNER JOIN dbo.tblPaymentReceipts ON dbo.tblPayment.Pay_ID = dbo.tblPaymentReceipts.Pay_ID
WHERE (dbo.tblPaymentReceipts.[Date] BETWEEN '1/1/2001' AND '12/31/2003')
GROUP BY dbo.tblPayments.Pay_ID, dbo.tblPaymentReceipts.[Amount Paid]
Select * FROM #temp_UNPaymentsA
GROUP BY Client_ID, SumOfAmtPaid, LastPaymentDate, [Amount Paid]
HAVING SUM(SumOfAmtPaid) BETWEEN 0 AND 1000
View 3 Replies
View Related
Feb 19, 2004
i am not getting a result back when i run the query below.
select * from users where DateCreated = '2004-02-19'
so i went into the table and looked at the record. for DateCreated field i have both date and time. ex: 2004-02-19 08:40:00
how can i select this record with out using the time in the select statement. what i want to see is how many users signed up for a day. any ideas?
View 5 Replies
View Related