Please Help With Comparing Date
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 visit the site only once?
- How many people visit the site only twice?
- How many people visit the site three time?
How do I do that?
please help
Thank you
View 8 Replies
ADVERTISEMENT
Jun 6, 2012
I need to compare the contents of a column.
I have a table with 1 column. Below are the sample contents..
DateInterval
2012-06-01 00:30:00.000
2012-06-01 01:00:00.000
2012-06-01 01:30:00.000
2012-06-01 02:00:00.000
2012-06-01 02:30:00.000
[code]....
as you can see, the records have a 30minutes time interval. i need to create a query to know if there are missing records in the table. so basically the result should be this:
DateInterval
2012-06-01 18:00:00.000
2012-06-01 20:30:00.000
if it is not doable, we can get the nearest record of all missing records like this:
DateInterval
2012-06-01 17:30:00.000
2012-06-01 20:00:00.000
or this:
DateInterval
2012-06-01 18:30:00.000
2012-06-01 21:00:00.000
or this:
DateInterval
2012-06-01 17:30:00.000
2012-06-01 18:30:00.000
2012-06-01 20:00:00.000
2012-06-01 21:00:00.000
View 6 Replies
View Related
May 19, 2008
I want to be able to compare today's date with the date that is in the database. Right now I have:
Select Field1, Field2
FROM table 1
Where Year(TS_Date)=Year('3/1/2006')and Month(TS_Date)=Month('3/1/2006')
Where I have to change the date every month. Is there a way to use GetDate or another type of code so it could automatically update every month.
Any suggestions would be very greatful.
View 13 Replies
View Related
Mar 29, 2006
I have a query that accesses a series of events in a gridview and would like to only show those that are in the future. I am looking to compare the date/time column against today's date in my SQL query.Any ideas would be great.ThanksOrbital
View 1 Replies
View Related
Mar 21, 2005
hi i did a
Code:
Select * from table WHERE =DatePart("yyyy",[somedate]) = Year();
to just get all the records which somedate is equals to this year but i get an error.. what's wrong with the syntax? thanks
View 5 Replies
View Related
Mar 18, 2004
I have two sets of dates to work with. One is an existing booking with a start and an end date. The other is a new booking with a start and an end date. I want to compare them and calculate how much overlap there is. If the overlap is over a certain amount (say 4 days), then I want to flag the user.
Is there any thing I can use in terms of a SQL query to assist in this comparison? I'm relatively new to SQL so I'm not entirely sure what functions and keywords are available to me to make this comparison.
View 3 Replies
View Related
May 8, 2001
Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?
View 4 Replies
View Related
Nov 9, 2006
hi guys,
i have a booking table which has the following columns...
booking
-------------------------------------------
dCheckin (format 11/9/2006 12:00:00 AM)
dCheckout (format 11/11/2006 12:00:00 AM)
when a new booking is entered, we want to make sure that the period entered does not conflict with an existing record.
not sure how to go about building the query required. any help would be greatly appreciated.
mike
View 4 Replies
View Related
Dec 18, 2013
Is there a performance impact (if so, how great is it) when comparing a date to a datetime data type?
An educated guess suggests yes, as there will be a type casting... but then again I don't believe there's an issue when comparing an int to a tinyint and there's an assumption these would play by the same rules?
This has only come about because I'm considering changing the data type used in my standard calendar script and this popped in to my head.
View 5 Replies
View Related
Jan 28, 2014
I have to write a where condition where i need to compare string with date
I have 2 columns FROMDATE and TODATE with datatype varchar(9)
The strings in the columns looks like YYYYMMDD+'1' or YYYYMMDD+'2' here 1 is Am and 2 is PM
i.e., 201401011 or 201401012
So I need to chop off last character before using them in WHERE condition.
Now I need to write a where condition like [if todays date is in between fromdate and todate columns then return rows.
if FROMDATE column is null it should take minimum date 1900/01/01 if TODATE is null then date should be 9999/01/01
The query i wrote is
select * from Table where ISNULL(SUBSTRING(VALIDTO,1,8),'19000101') > = getdate()
AND ISNULL(SUBSTRING(VALIDTO,1,8),'99991231') < convert(varchar, getdate(), 112)
but it shows no data...
View 9 Replies
View Related
Aug 25, 2007
Hello! I have a field "End" in my database that is mapped as DateTime and allows nulls. Now I want to do a SQL-Select (in a SqlDataSource) like SELECT * FROM My_Table Where (([End] = @EndDate) OR ([End] = null)) @EndDate is a valid DateTime, but the second OR condition doesn't work. What is the best way to check if the [End]-field is empty or null? Thank you very much!
View 1 Replies
View Related
Jan 31, 2014
how to write condition for self table year records, such 2012 name and acctno match with 2013 name and acctno then total, provided below,
create table #tab1 (MasterKey int, AcctNo varchar(12),name varchar(25), SumaofShares numeric, request_dat datetime )
--drop table #tab1
insert into #tab1 values (1000, 100,'Tom', 2500, '10/01/2012')
insert into #tab1 values (1001, 101,'Bat', 1550, '08/11/2012')
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
insert into #tab1 values (1003, 103,'Vat', 1750, '04/15/2012')
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
[code]....
i would like to get 4 columns output
how to get sumofshares (#tab1) and TotalOutStanding(#tab2) summ up with these values,
MasterKey (#tab1) and IssueKey (#tab2) are like primary key and foreign key
so the request is
need to calculate, sumofshares (#tab1) and TotalOutStanding(#tab2) as below
1)ShareBenefist = U and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts UN Veriverted'
2)ShareBenefist = V and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts Veriverted'
3)ShareBenefist = N and year( request_dat) in (2012 , 2103) and (Name for 2012 should match with 2013 name and 2012 Acctno should match with 2013 accounno) in (#tab1)
then '2012 and 2013 accts NONVERT'
4)year( request_dat) =2102 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 last year accounts'
5)year( request_dat) = 2013 and Name and Acctno not match with 2013 account name and acctno (#tab1)
then '2012 This year accounts'
for ex 1) the below accounts in #tab1 has both 2012 and 2013 and acctno same in both years and name is same in both years so it is condired as
insert into #tab1 values (1012, 100,'Tom',800, '08/22/2013')
for ex 2)
insert into #tab1 values (1013, 101,'Bat',550, '09/15/2013')
for ex 4) 2012 records there is not match acctno and name in 2013 recods
insert into #tab1 values (1002, 102,'Kit', 1600, '06/12/2012')
for ex 5) 2013 records there is no match of name and acct no with 2012 records
insert into #tab1 values (1010, 104,'Sim',200, '04/21/2013')
insert into #tab1 values (1014, 100,'Pet',200, '02/21/2013')
insert into #tab1 values (1016, 110,'Sun',800, '03/22/2013')
insert into #tab1 values (1017, 111,'Bet',550, '12/15/2013')
Expected Results (just for format)
AcctTypeDescription,SumofShares, OtotalutStand
'2012 and 2013 accts UN Veriverted',2700,234
'2012 and 2013 accts Veriverted' ,2890,234
'2012 and 2013 accts NONVERT' ,4533,325
'2012 last year accounts' ,2334,567
'2012 This year accounts' ,2222,877
View 9 Replies
View Related
Sep 9, 2015
I am trying to pull the records which are being affected i.e, comparing the values and if not same then populating the record.
I am using the below condition in where clause however i am getting runt time error as "Conversion failure when converting date and/or time from character string"
Condition in Where clause:
cast(isNull(tab1.Col1,'') as datetime) <> cast(isNull(tab2.col1,'') as datetime)
Note: Both col1 columns are of type nvarchar
View 6 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
Jun 26, 2006
Hello,
I am trying to retrieve the data that are not more than 3 months. How do I do this? The closest thing that I can do is...
(dbo.CLASSIFIEDADS.PostDate > CONVERT(DATETIME, '2006-03-26 00:00:00', 102))
I want to be able to put 3 months in there somehow...
Thanks in Advance!
View 2 Replies
View Related
Aug 29, 2004
Hi,
I have a field in database money. When I enter value for it the amount entered is for example 20.000. How can I compare this value with noraml vaules i.e. like 20 in my search engine. Will I need to convert it to varchar and then compare it or is there some other way. Also if I need to convert it to varchar, how can I do it?
Thanks in advance,
Uday
View 6 Replies
View Related
Jan 29, 2005
hi ... please look at it :
<< The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. >>
ok ... it was my error mess, but i just wrote this code :
***********************************************************
Dim conPubs As SqlConnection
Dim cmdSelect As SqlCommand
Dim strSelect As String
conPubs = New SqlConnection ("Server=localhost;uid=ggggg;pwd=uuuu;database=eeee")
strSelect = "Select username From userpass Where username = '" & usernametxt.Text & "' And password = '" & passtxt.Text & "'"
cmdSelect = New SqlCommand( strSelect, conPubs )
conPubs.Open()
if Not(cmdSelect.ExecuteScalar() IS Nothing) then 'findeduser.text
response.redirect("welcome.aspx")
conPubs.Close()
else
msg.text="ID or Pass is incorrect!!"
conPubs.Close()
end if
***********************************************************
what is wrong?
can you help me?
me : mhamini@gmail.com
View 2 Replies
View Related
Jan 28, 2006
I am wondering how I would create a SELECT that will select the most recent date from one of two tables. For example, table1 has a field called LastUpdate and table 2 has a field called LastUpdate. I need to grab only the most recent date. I tried this using an inner join...but that didn't work because it only picks the lastupdate form one table only. talbe1 and table2 are tied by table2.table1id.
Can anyone help?
View 7 Replies
View Related
May 23, 2006
Hi All,
I have a database field (datestamp) which returns the date the records were inserted into the database. The datestamp was created with the now(); function in .net and is in the following format: 5/23/2006 2:27:45 AM
I basically want to return all records that were inputted more than 28 days ago. I have had alook though some other posts and below is the closest query that i could find but unfortunately it does not work for me.
SELECT id, datestampFROM table WHERE datestamp > DateAdd(d, 28, GetDate())
Thanks in advance,
Jake
View 2 Replies
View Related
Mar 1, 2001
Hi Guys,
I'm afraid the schemas of the Development and Production versions of a database are in fact diferent.
How may I compare two database schemas?
Thanks in advance !-)
View 1 Replies
View Related
May 3, 2001
Hi ,
I have three tables T1 , T2 AND T3. T3 is having fields as a combination of T1 and T2 fields.How can I compare T1 and T2 field values with T3 FIELD VALUES.
View 4 Replies
View Related
Jul 10, 2001
How do i compare 2 dates without comparing their Time portions. I have a Datetime column in my table which for example has values :-
6/6/2001 7:23:42 PM
6/6/2001 8:01:08 PM and so on....
I have a Stored Procedure in which i am trying to fetch values from this table. The SP has 2 DateTime parameters @DateFrom and @Dateto. This SP is called from a Web page. On the Web Page the user just enters mm/dd/yyyy values for the 2 Date parameters. Therefore the Time portions defaults to 12:00 AM. So when the user passes 6/6/2001 as Date From and 6/6/2001 as Date To values, he doesn't get back the 2 records mentioned above since the Time portion makes the 2 records fall out of the date range.
Is there a way to just do a comparison on the Date portions i.e. give me all the records for 6/6/2001 irrespective of the time. I don't wan't to do individual comparisons for Day then Month and then Year.
Thanks
Sanjay.
View 5 Replies
View Related
Sep 1, 2003
Hello all,
I'm new to SQL Server so if the following sounds stupid then apologies. I am trying to design a query which compares columns and filters according to the result of the comparison. We are a UK based charity that provides financial help to families with disabled children (www.familyfund.org.uk). We have a large database (250,000 entries) which we know contains some duplicate/split files from a recent migration. We need to identify these files but not delete them. Currently I am using the following:
SELECT dbo.Families.famId, dbo.Address.street, dbo.Children.childId, dbo.Address.postcode
FROM dbo.Children INNER JOIN
dbo.Families ON dbo.Children.family_no = dbo.Families.famId INNER JOIN
dbo.Persons ON dbo.Families.famId = dbo.Persons.famId INNER JOIN
dbo.Address ON dbo.Persons.addressId = dbo.Address.addressId
WHERE (NOT (dbo.Children.eligStatus IN (3, 4)))
GROUP BY dbo.Children.childId, dbo.Address.postcode, dbo.Families.famId, dbo.Address.street
HAVING (dbo.Address.street IS NOT NULL)
ORDER BY dbo.Address.street
Obviously this returns all 250,000 records and then we have to search manually. We would like to run a query which compares families.famID to address.street so that where famId has more than one address attched it is returned to the results grid. Does this make sense? is it possible? Any help would be gratefully received
Thanks in advance
Mark
:confused:
View 8 Replies
View Related
Mar 22, 1999
I have a Development and Production database and they are a little out of sink. Does any one know of a way to compare two databases (tables, fields, sp) and report the differences? Thanks in advance.
View 3 Replies
View Related
Sep 28, 2005
Hey all,
Trying to compare unique fields from two databases.
Basically what i'm trying to do is get all of the id's out of one field that don't exsist in the 2nd database.
so I have this query
Code:
select Distinct Id
from table1
where ID!= (select Distinct ID from table2)
I'm getting this error
Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Now I don't understand why because then I query
select id from tables 2
I only get 1 value for each row.
Now you should know, the two columns in either table are different, in one of them the first value is "1" in the other the first value is "00000001" although I don't think that should effect anything.
Any idea's?
Thanks
View 1 Replies
View Related
Dec 10, 2004
i am using sql server ver 7
i am trying to do
select *
from independent_investment_certificate_temp
where independent_investment_certificate_temp.ticker_key = 31
and convert(varchar(40), cast(independent_investment_certificate_temp.maturity_date AS datetime),107) >
convert(varchar(40), cast('2006-12-10 10:29:50.733' AS datetime),107)
independent_investment_certificate_temp.maturity_date value is '2005-01-21 00:00:00.000'
the query above returns a value even though '2005-01-21 00:00:00.000' is clearly < '2006-12-10 10:29:50.733'
but why can anyone plz explain.. how can i compare dates stripping tyhem of the time so that all dates on the same day will be
equivalent regardless of the time
View 1 Replies
View Related
Aug 25, 2005
Hi, i got this query below, which I'd like to use to compare two sets of date...
select count(*) as rec, convert(char(6),dateEntered,13) as dateEntered from EmailTracker where chtype = '1' AND convert(char(12),dateEntered,13) >= '"& stdate &"' AND convert(char(12),dateEntered,13) <= '"& endate &"' group by convert(char(6),dateEntered,13)
the format of the stdate and dateEntered (a datetime datatype) looks like - 25 Aug 2005
right now, the query simply uses the first 2 letters of the date to fetch the record. That would not do the job as i want the thing to compare the whole lot! not just the 1st two letters...
Any help pls?
View 5 Replies
View Related
Aug 2, 2004
Hi everyone,
I have 2 seperate databases and I need to check for rows that are different from each other in a table.
I used access to link the tables in a database and am using queries to check the tables. However, I am having trouble formulating the SQL. What I want to do is not just check for the ID field to see if it exists, but to make sure the whole row exists. How can I form an SQL statement for this?
I tried something like:
Select * from table1 where Column1 NOT IN (Select Column1 from Table2) AND Column2 NOT IN (Select Column2 from Table2). However, I do not think this is correct. I want to make sure that the rows are compared, not individual values.
Any help would be appreciated.
Thanks,
Pankaj
View 5 Replies
View Related
Oct 29, 2004
IS there an easy way to compare two tables in sqlserver? I only need to display items that are different between table a and b.
thanks in advance for your help!
View 9 Replies
View Related
Dec 16, 2004
Does anyone know of a quick and easy to compare 2 datetime values based only on the month and year.
For example,
FromDate = 11/30/2004
ToDate = 12/30/2004
I just need to compare the 11/2004 to 12/2004 using function like <=, =, >=, etc.
Any suggestions?
Thanks
View 5 Replies
View Related
Jan 15, 2007
whats the best way to compare two row values and concatenate those two
For example
Table1
-------
Col1 Col2
----------
A 1
A 4
B 2
C 3
A 5
I need a query to return something like
"where (A=1 or A=4 or A=5) and (b=2) and (c=3)"
Thanks in advance
View 11 Replies
View Related
Jan 14, 2004
Hi all,
Sql server 7
i have two databases best and books.Most of the tables present in best are in books except some.
i have been given a task to list out the tables and columns of which are present in best database and not in books database.
Pls suggest me the simplest and quickest way to do this.
this is very urgent.
waiting for reply.
TIA
Adil
View 4 Replies
View Related
Apr 4, 2008
I will try to explain my problem as best as possible without going into too much detail.
Basically I have two tables,
AgentSchedule
AgentPunchData
These tables both contain agent names.
The schedule table has a column called "SHEND" which is a DATETIME datatype which identifies when an agent shift should end.
The entries all have a date attached which means nothing, for example "12/30/1899 9:00:00 PM"
The PunchData table has a column called "LOGOUT" which is also a DATETIME, the entries will have the real date and look something like this: "3/28/2008 9:23:00 PM"
I need to strip the date out of these functions so I can compare the times. I need to query the databases and return any instances where the LOGOUT time is > the shift end time (SHEND).
So far nothing I've tried has been successful. I'm completely stumped, I've tried so many different things and nothing compares the two times correctly. SQL DATETIME is the biggest pain in the ass, I wish we had SQL 2008 so I could just use TIME.
View 6 Replies
View Related