Grouping Data And Selecting Highest Date

Aug 20, 2007

In SQL 2005 I have the following view:

SELECT TOP (100) PERCENT StockCode, Warehouse, QtyOnHand, QtyAllocated, QtyOnOrder, QtyOnBackOrder, DateLastSale, DateLastStockMove,
DateLastPurchase
FROM dbo.MBL_VW_AgedStock_Sales
ORDER BY StockCode

This basically shows a list of stock codes (there are multiple stock codes the same) and the last sold date. What i need to do is group the stock codes which are the same together, and show the latest date.

For example I could have the following:

STOCK CODE Last Date Sold

PC1113 11/01/2007
PC1104 15/03/2007
PC1113 15/02/2007

What I want to see is a list that shows PC1113 with its latest sold date, i.e.

STOCK CODE Last Date Sold
PC1113 15/02/2007
PC1104 15/03/2007

Any ideas?

Thanks
Kris

View 3 Replies


ADVERTISEMENT

Selecting Top 5 Highest Rows

Sep 25, 2006

I have a table stock, on the table I have company_name, stock_value, sector.
Now I want to get top five rows from this table depending on the five highest value of stock_value and for each sector. The query has to run on both oracle DB and Microsoft SQL Server with top priority MSSQL.
I will appreciate if you help me on this

jideofor

View 2 Replies View Related

Keep Duplicate With Highest Score Fuzzy Grouping

Jan 22, 2012

I have recently decided to dedupe my data but i am having a problem after running fuzzy grouping with the query on updating which duplicate to keep

_key_in is unique, _key_out is the duplicates so for example:

_key_in , _key_out , name , score , dedupe
1 , 1 , ron , 10 , purge
2 , 1 , ronn , 15 , keep
3 , 3 , john , 5 , keep
4 , 4 , matt , 15 , keep
5 , 4 , mat , 10 , purge
6 , 4 , matt , 15 , purge

I want to keep the _key_out with the higher score by setting the field de_dupe to 'keep' and the remainder to 'purge'. The score can also be the same within a duplicate so in the case it is the same i just need to keep one it doesnt matter which one. The query i have below nearly works but it marks duplicates with the same score as keep.

Code:
UPDATE b
SET b.dedupe_result = 'keep'
FROM
[BusinessListings].[dbo].[MongoOrganisationACTM1Destination] b
INNER JOIN

[Code] ....

View 2 Replies View Related

Selecting Highest ActionID For Each TradeID

Mar 26, 2008



I have a table like
Tradeid ActionID
3664 58096
3665 58096
3666 58097
3667 58097
3668 58098
3669 58098
I want to select the only the rows representing TradeID with the highest ActionID
like
3665 58096
3667 58097
3668 58098

I tried using
select distinct tradeid,actionid
From
cct
Where ActionID = (SELECT MAX(ActionID)
FROM cct1
WHERE cct1.TradeID = cct.TradeID)
group by tradeid,actionid

but the result is not correct

please help

View 8 Replies View Related

Data Not Selecting On Current Date

Oct 27, 2014

The following is the sql being executed in my Crystal report. There seems to be an issue with the same date request. Sometimes it shows data, other times not. We have data every day, we are a mass market company. Is there anything i can do for the sql to do select when from and to dates are the same?

SELECT "OEHIS1"."ODORD#", "OEHIS1"."ODORDT", "OEHIS1"."ODNTU$", "OEHIS1"."ODSHP#", "ICPRT1"."IARC11", "OEHIS1"."ODORDD", "ICPRT1"."IARCC4", "OEHIS1"."ODQTY#", "OEHIS1"."ODRQSD", "MFHHMH"."MHAWGT", "OEHIS1"."ODPRT#", "OEHIS1"."ODPRLC"
FROM ("S10M10"."ASTCCDTA"."EODDETAILS" "OEHIS1" INNER JOIN "S10M10"."ASTDTA"."ICPRT1" "ICPRT1" ON "OEHIS1"."ODPRT#"="ICPRT1"."IAPRT#") INNER JOIN "S10M10"."DLIB"."MFHHMH" "MFHHMH" ON "OEHIS1"."ODORD#"="MFHHMH"."MHORDP"

[Code] ....

View 4 Replies View Related

Need Help Selecting Data With Date -based Where Clause

Nov 18, 2003

OK. I have this query, works on another box fine.

SELECT *
FROM bookkeep RIGHT OUTER JOIN
acraccts ON LEFT(bookkeep.accnum, 9) = acraccts.p_accnum
WHERE (bookkeep.busdate = '03/09/10') AND (bookkeep.tradetype = 'S')

on my sql box, if i run it, i get no data.

i figured out that if i change the where clause to (bookkeep.busdate='2003/09/10') it works

OR

if i simply put SET DATEFORMAT YMD on the first line before the SELECT * that it also works.

my problem is the basic query is hard coded and i really can't change it.

is there a global sql server setting that will make my sql 2000 sp3 box recognize '30/09/10' as 2003/09/10?

View 1 Replies View Related

Date Range Problem While Selecting Data

Feb 14, 2008

When im using the below query im getting the output, but when i change the starting date to 2006 I'm not getting the data for 2007 though it falls between the 2006 and 2008 range...



select * From dbname..tbl where date>= '03/jan/2007' and date <= '11/feb/2008' and Status= 'C' and ID is not null

AND (ACCOUNT = '25869' or ACCOUNT = '0' + '25869' )
Check and post your comments ASAP...

View 11 Replies View Related

Selecting With Grouping

Mar 4, 2014

I have a table and I need three columns:AdEnrollID (Foreign Key), SyStatchangeID (Primary KEY) and EffectiveDate (DateTime). I need the MAX(EffectiveDate) group by AdEnrollID but I also need the systatchangeID for that row.

here is my query:
Select AdEnrollID,SyStatChangeid, MAX(EffectiveDate)
from systatchange where EffectiveDate < '8/1/2013' and adenrollID=47964
Group by grouping sets ((SyStatChangeID, systatchange.AdEnrollID))

but it gives me a lot of results (I know, I group by systatchangeID and is going to include them all) Here is the result:

AdEnrSyStat(No column name)
479642749562012-08-07 12:44:36.787
479642772862012-09-05 09:32:02.480
479642786212012-09-13 13:45:11.840
479642791062012-09-19 14:58:33.080
479642858232012-12-07 15:14:01.087

[code]....

I am only interested in the one in bold. How can I do this.

View 3 Replies View Related

T-SQL (SS2K8) :: Selecting Data By Date For Last Five Days AND Avoiding Weekend Dates

Apr 16, 2014

What I am trying to do: Obtain attendance percentages for schools for the last five days. The outcome would look like this:

DISTRICTGROUPING, SCHOOLNAME, 5 DAYS AGO PCTG, 4 DAYS AGO PCTG, 3 DAYS AGO PCTG, 2 DAYS AGO PCTG, 1 DAY AGO PCTG
I am using nested subqueries for each day as follows: (total enrollment-total absent/total enrollment)
,(
((SELECTCOUNT(*)--GET TOTAL ENROLLMENT COUNT FOR SPECIFIED DATE

[Code]....

The query works with the following exceptions:

My issues are:

1. Avoid the "division by zero" error. This can occur if a school is closed for a day or if a smaller school has no absences for a day.

2. Avoid weekend dates. I need the query to display only weekdays

3. Currently I am using "PERCENTAGE 5: as a column header whereas I need the actual date as the header.

View 6 Replies View Related

SQL Server 2012 :: Selecting Data From A Change Log Where Date Falls Between Two Rows

Aug 29, 2014

I need to extract a price from a package solution table that was current on a certain date.

Columns are:

Product_Reference int,
Change_Date int, -- Note that this is in yyyymmdd format
Price decimal

So for one items you would get

Product_ReferenceChange_DatePrice
100014200401281.59
100014200605131.75
100014200802121.99
100014200906252.35
100014201002242.50
100014201107151.10
100014201205151.15

The challenge is to return the price of the item on 20070906. In this example 1.75.

I've tried joining it to itself

SELECT DISTINCT p1.[Product_Reference]
,p1.[Change_Date]
,p1.[Price]
FROM PHistory p1
INNER JOIN PHistory p2
ON p1.Product_Reference = p2.Product_Reference
WHERE p1.Product_Reference = 100014
AND p1.Change_Date >= 20070906
and p2.Change_Date < 20070906

But it returns the price above and below that date.

View 3 Replies View Related

Transact SQL :: Selecting Latest Date But Over Another Date Column Including Nulls?

Nov 26, 2015

CREATE TABLE #Dateissue
(ID int,
Code nvarchar (20),
Datein datetime,
Declined datetime )

[Code] .....

I have a table here.  I want  find a way of getting the latest date, when the code is the same.  If the Declined date is null.  Then I still want the latest date.  E.g. ID 3.  

If the declined date is filled in.  Then I want to get the row, when the Datein column value is greater then the declined date only.

I tried grouping it by max date, but   i got an error message when trying this out.  Against the code  

WHERE MAX(Datein) > Declined

An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.  What do I need to do to get both my outputs working? 

View 9 Replies View Related

Problem Inserting Integers And Date In A Sql Server 2005 Datatable Row And Selecting It Afterwards Based On The Date

May 4, 2007

Hi,
 
I have soma ado.net code that inserts 7 parameters in a database ( a date, 6  integers).
I also use a self incrementing ID but the date is set as primary key because for each series of 6 numbers of a certain date there may only be 1 entry.  Moreover only 1 entry of 6 integers is possible for 2 days of the week, (tue and fr).
I manage to insert a row of data in the database, where the date is set as smalldatetime and displays as follows:  1/05/2007 0:00:00 in the table.
I want to retrieve the series of numbers for a certain date that has been entered (without taking in account the hours and seconds).
A where clause seems to be needed but I don’t know the syntax or don’t find the right function
I use the following code to insert the row :
 
command.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime, 40, "LDate"));
command.Parameters[6].Value = DateTime.Today.ToString();
command.ExecuteNonQuery();
 
and the following code to get the row back (to put in arraylist):
 
“SELECT C1, C2, C3, C4, C5, C6 FROM Series WHERE (LDate = Today())�
 WHERE LDate =  '" + DateTime.Today.ToString() + "'"
 
Which is the correct syntax?  Is there a better way to insert and select based on the date?
 
I don’t get any error messages and the code executes fine but I only get an empty datatable in my dataset (the table isn’t looped for rows I noticed while debugging).
Today’s date is in the database but isn’t found by my tsql code I think.
 
Any help would be greatly appreciated!
 
Grtz
 
Pascal

View 5 Replies View Related

What Is The Highest Value Of An Int Data Type

Feb 27, 2007

Can someone tell me what the highest value (number) is for an int data type in sql server 2005?

View 2 Replies View Related

Highest Speed Data Access

Jan 21, 2008

I have inherited a half-finished sql-server based project from a recently departed coworker. The critial point of this project is one app thread that reads barcodes, queries a single table in the database for the one record with that code as its primary key, and makes desisions based on that record. The faster that I can make that go, the better the process will run, up to a max rate as high as 20 queries per second if that were possible. I have a limited
general knowledge of sql, but very little of sql-server express.

My question is what is the best way with sql-server to maximize my single-table request rate?? On some other databases I could create an in-memory temp copy of the table with trigger events on the main table to keep the copy in sync, or I could do an initial select on the entire table to hopefully get the table into cache memory, or I could use some kind of ado-like table on the app side (but do I really gain much of anything doing this??)

With SQL server, what is my best approach to maximize my throughput under these conditions??

FYI..The c++ app uses direct odbc calls to a localhost database. Table theoretically could have 75000 ever-changing records in it. There are 5 or 6 other processes also hitting on this table, but at a far more lakadaisical (say once every 10 seconds level) rate.

View 3 Replies View Related

Date Grouping

Jan 3, 2007

Hello All,

Noob here. Trying to group by date in report and it is not working as expected. The date fields include a date/times i.e. 12/23/2006 9:45:00 AM. I can change the date properties to make the data appear as 12/23/2006, but when I group on date, it returns multiple rows showing the same date instead of just one row with the one date. The data is aggregated for the grouping so it seems like it should work properly. Here is an example of what I am trying to do.



Current...

Date Data

12/23/2006 9:45:00 AM 12

12/23/2006 10:00:00 AM 8

12/23/2006 10:15:00 AM 5



Want it to be...

Date Data

12/23/2006 25



Using SQL Server 2000 and RS2000



Thanks,

Clint

View 5 Replies View Related

Grouping Rows By Just The Date

Mar 2, 2001

I store data in a table using a column named InsertTimestamp which is a datetime format. I now want to report on rows by just the date. I have been able to do this by converting the datetime like such:
convert(varchar, inserttimestamp, 107)
This reurns the data correctly however is very ineffiecnet. DOes anyone know another easy way around this dilemna???

View 1 Replies View Related

Grouping By Date Period

May 12, 2006

I'm using SQL Server 2000.

Example table:
PeopleID Date Status
1 2004-01-01 True
1 2005-01-01 True
1 2006-01-01 True
2 2004-01-01 True
2 2005-01-01 False
2 2006-01-01 True

I'm trying to find a way to query whether or not someone has had a specific status for 3 years in a row. As you can see from the table above, PeopleID 1 has had a "Status" of "True" for 3 years in a row, whereas PeopleID 2 hasn't--there was one year where they had "False".

I'm wondering I can query this, or if I'm going to have to scan the records manually. :(

I suppose I could write a stored procedure and do some looping too.

Appreciate any help, thanks!

View 2 Replies View Related

Earliest Date And Grouping

May 7, 2008

Hi I am having trouble and I don't know why.

I have this query which I pasted below. I need to find the earlist effective date (pcsp_eff), but I need to show all of the fields below in my report like a flat file. I know ususaly when you use Max/Min you have to have a group by, would I group by everything that is in my select statement?

SELECT Distinct
dbo.pcs.pcs_id1,
dbo.pcs.pcs_lname AS [Last Name],
dbo.pcs.pcs_fname AS [First Name],
dbo.pcsp.pcsp_eff AS [Effective Date for Provider],
Min(pcsp_eff) as "earliestEffectivedate",
dbo.pcst.pcst_trm1 AS [Tracking Thru Date],
dbo.pcst.pcst_dat3 AS [Re-cred Letter Sent Date],
dbo.pcst.pcst_dat7 AS [Re-cred Complete Date],
PRO_STATE as "State",
PRO_COUNTY as "County"--, PCSP_NET

FROM dbo.pcs INNER JOIN
dbo.pcst ON dbo.pcs.pcs_id1 = dbo.pcst.pcst_id1 INNER JOIN
pcsp ON pcs.pcs_id1 = pcsp.pcsp_id1 left Join
dbo.pro ON pcs.pcs_id1 = pro.pro_id1

WHERE
(CONVERT(CHAR(10), dbo.pcst.pcst_dat3, 110) <>'03-23-1977') and
(CONVERT(CHAR(10), dbo.pcst.pcst_dat7, 110) = '03-23-1977') and
(pcsp.pcsp_prd = 'DGH') AND
--(pcsp.pcsp_id2 = '0001') and
PCS_CTL = 'I' and
pcsp_NET <> 'DACFP' and
pcs_id1 = '00004307'

Group by pcs_id1

View 2 Replies View Related

Grouping By Date Range

Mar 14, 2008

My company is unusual in that our accounting periods are not actual months. We have what we call "Red Fridays." These are spaced 3-5 weeks apart. So, my company doesn't care what happened in the month of April, but they care what happened between April 4 and May 2 because these are the Red Fridays.

So, I have created a database with a table called "RedFridays" with the dates for this year. I want to combine this with various tables in our ERP database. I use a Left Outer Join between the Red Friday Dates and the corresponding date in the ERP database.

I need to create a custom grouping formula which accomplishes the following:

1. Subtract a certain number of months from today's date to determine which Red Friday would be the correct starting date.
2. Group records by date between that Red Friday and the second one. This would be listed as something like "Month 1".
3. Continue grouping in this way to the present date and that Red Friday range.

Can anyone point me in the right direction? Any help would be greatly appreciated.

View 5 Replies View Related

Problem Grouping,,,,,,,with Date

Mar 19, 2008

Here's my sql which works

SELECT tblFileRequests.Dept, tblFileRequests.Division, tblFileRequests.Sect, COUNT(*) AS Expr1
FROM tblFileRequests LEFT OUTER JOIN
tblFileRequestDetails ON tblFileRequests.MovementId = tblFileRequestDetails.MovementId
GROUP BY tblFileRequests.Division, tblFileRequests.Sect, tblFileRequests.Dept
ORDER BY tblFileRequests.Dept, tblFileRequests.Division, tblFileRequests.Sect

I also want to include tblFileRequestDetails.DateOut but this cause my grouping to go haywire. How can I include it ? Ultimately I want to create a stored procedure and crystal report based on it. Thanks

View 20 Replies View Related

Grouping On Date Without Time

Apr 5, 2007

Hello,



I have the following problem.

I a making reports based on a database that i do not control.

In that database i have a table with statistical data including a field with datetime informtion.

The format of the data I receive is "5/04/2007 7:43:27".



In my report i want to create a group which groups my event by date : "05/04/2007"

In my output i always get subgroups by date & time so "5/04/2007 7:43:27", "5/04/2007 7:43:28", ....



How can i group only on the date.



Vincent



View 13 Replies View Related

Grouping Date Field By Day Only, Not Time

Jan 17, 2002

I'm adding up quantities of an item that are entered in one after another, so the date is the same, but the time differs.

I used the "first" function in access which works the way I want, but sql7 doesn't use the same function. The "convert" function does not work in access but Here is the gist of the query:

SELECT first(CONVERT(varchar,transactions.tran_date,101)) AS [trandate], transactions.tran_type,
SUM(transactions.qty) AS totqty,...etc.

thanx,

Herb

View 1 Replies View Related

Transact SQL :: Sum Amount By Grouping Date

Oct 3, 2015

I have a table that have customer name and their bill amount

a) tblBilling

which shows records like below (Billing Dates are shown in Year-Month-Day format)

Invoice   Customer             BillingDate       Amount            Tax
--------------------------------------------------------------------------
1             ABC                       20015-10-2           1000.00            500.00
2             DEF                        20015-10-2           2000.00        1000.00
3             GHI                        20015-10-2           1000.00            500.00
4             JKL                         20015-10-3           5000.00          2500.00
5             MNO                     20015-10-3           1500.00            750.00
6             PQR                       20015-10-4            500.00            250.00
7             STU                        20015-10-4           1000.00           500.00
8             VWX                      20015-10-4            2500.00         1250.00

I want to perform a query that should SUM Amount and Tax Colums by date basis, so we could get the following result

 BillingDate       Amount            Tax
--------------------------------------------------------------------------
20015-10-2           4000.00            2000.00
20015-10-3           6500.00            3250.00
20015-10-4           4000.00            2000.00

View 3 Replies View Related

Selecting A Date

Mar 23, 2006

Hi --
What is the proper way to select results with a date in the where statement when the datatype of the column is datetime?
select * from table where date_field = '3-23-2006'     does not get any results.
 
Thank-you for your help.
 

View 4 Replies View Related

Selecting Last Date

Dec 26, 2006

Hello,I have a couple of tables. The client tables and the contactedtables.I am not sure how to start on this, what I need is a way to query allmy clientsthen show any client that the last visit and or called day is greaterthan 30 days.Now it gets confusing, Suppose the client was visited more than 30 daysagobut was called only 10 days ago, I really would like to have thisappear on the samequery.So the report would look similar to this below.Visit Date Called DateClientA 2006-11-02 2006-12-16ClientB 2006-12-17 2006-10-30ClientC 2006-10-15 2006-10-16ClientDFields (Simplified)Clients: Name, Address, Phone.Contacted: Name, Date, Visit, Call.I need to query all l names, but I only need the last visit and lastphone call. Then determine if either date is greater than 30 days ifso, display the last date of each type of contact. And if there isnothing for the client in the contacted table this needs to show also,ClientD.Any tips, ideas would be greatly appreciated....ThanksIce

View 9 Replies View Related

Selecting Max/Min Date

Dec 17, 2007

I'm trying to return the Max and Min Date value for each Item in a History table. Thanks for any help. Example:





Code Block

ID Item Date
1 A 12/1

2 A 11/1

3 A 10/1

4 B 9/1

5 B 8/1
6 B 7/1
The result I would be expecting is:





Code Block

Item Max Min
------------
A 12/1 10/1

B 9/1 7/1

View 1 Replies View Related

Grouping By The Date Portion Of A Datetime Datatype

Jul 13, 2000

Hi,

I have a requirement to be able to select and group records by the date portion of a datetime field. ie ignore the time when grouping so that all records lodged on a particular day are seen together.

I have been able to do this by

- converting the datetime data to the number of days since a given date
- inserting this into a temporary table
- retrieving the the data from the temporary table
- convert the data back to a date using DATEPART to display dd/mm/yy

This then gives me the data grouped as required but seems to be a very difficult solution - Is there an easier way??

Thanks in advance
jan

View 3 Replies View Related

Combing Queries - Grouping By Date Ranges

Aug 2, 2004

Masters,
The below queries return the data that I seek, but I have no idea how to combine them into a single query.


SELECT SUM(TOTALSVCAMT) - SUM(TOTALPAYMENTAMT) - SUM(TOTALADJAMT) as [0 to 30]
FROM MDM2
WHERE DATEDIFF(day, SERVICEDATE, getdate()) between '0' and '30'

SELECT SUM(TOTALSVCAMT) - SUM(TOTALPAYMENTAMT) - SUM(TOTALADJAMT) as [31 to 60]
FROM MDM2
WHERE DATEDIFF(day, SERVICEDATE, getdate()) between '31' and '60'

SELECT SUM(TOTALSVCAMT) - SUM(TOTALPAYMENTAMT) - SUM(TOTALADJAMT) as [61 to 90]
FROM MDM2
WHERE DATEDIFF(day, SERVICEDATE, getdate()) between '61' and '90'

SELECT SUM(TOTALSVCAMT) - SUM(TOTALPAYMENTAMT) - SUM(TOTALADJAMT) as [90+]
FROM MDM2
WHERE DATEDIFF(day, SERVICEDATE, getdate()) > '90'


Any assistance that can be provided will be greatly appreciated.
Grasshopper

View 1 Replies View Related

Select With Grouping For Multiple Date Columns

Sep 22, 2007

Hi All,

Thanks for dropping by my post.

I have a table which is of this form.










ID
MS030_A
MS030_F
MS036_A
MS036_F
MS040_A
MS040_F

ZZ0023
2/16/06
2/16/06
8/10/07
8/10/07
11/21/05
11/21/05

ZZ0031
8/10/07
4/5/07
8/9/07
8/9/07
3/22/07
3/22/07

ZZ0077
8/9/07
9/7/07
8/10/07
8/10/07
8/10/07
9/7/07

ZZ0078
8/10/07
9/7/07
8/9/07
8/9/07
8/9/07
9/7/07

ZZ0079
8/9/07
8/10/07
10/26/05
10/26/05
8/10/07
8/10/07

ZZ1030
3/31/05
8/10/07
9/1/05
9/1/05
8/9/07


ZZ1033
3/24/06
8/9/07
8/9/07
8/9/07
3/31/05


ZZ1034
8/10/07
8/10/07
8/9/07
8/9/07
3/24/06


ZZ1037
8/9/07
8/9/07
9/24/07

9/24/07


ZZ1040
10/26/05
10/26/05
9/24/07

9/24/07


ZZ1041
9/1/05
9/1/05
9/24/07

9/24/07


ZZ1042
8/9/07
8/9/07
9/24/07

9/24/07
11/21/05

The goal is to group all this transactions by Month and Year.

Something like this....







MS030_A
MS030_F
MS036_A
MS036_F
MS040_A
MS040_F
Month
Year

3
2
2
2
2
2
1
2006

4
4
7
9
8
9
2
2006

10
10
6
8
8

3
2006

4
4
5
5
3
2
4
2006

5
6
8
3
7
1
5
2006
For just one date column it is pretty straight forward i.e., just do a select count and group by DATEPART ( Mm, DateField)
but for multiple columns i am in a total fix....

can please someone help me out...

appreciate your help

View 6 Replies View Related

Selecting The Earliest Date

Jun 12, 2008

 I'm having a mental block on a select statement.I have a table with the following columns:KitId int
LotNo varchar(10)
DateReceived smalldatetimeIt is possible to have many rows with the same LotNo but a differing DateReceived I need to write a select statement that returns the KitId for a given LotNo with the earliest DateReceivedso if I had rows:KitId =1, LotNo = 123, DateReceived = 11th May 2008KitId =2, LotNo = 123, DateReceived = 28th May 2008KitId =3, LotNo = 125, DateReceived = 28th May 2008KitId =4, LotNo = 127, DateReceived = 28th May 2008KitId =5, LotNo = 123, DateReceived = 12th June 2008I would want to retrieve KitId=1 if I provided LotNo 123 as a parameter Whilst it should always be the case that the LotNo with the earliest date will have the lowest KitId I cannot guarantee that will be the case so going for the lowest KitId isn't an optionCan one of you SQL gurus provide me with the statement I need?ThanksNeil  

View 2 Replies View Related

Selecting Date Of Birth

Jun 14, 2008

I have table with column Date Of Birth its datatype is smalldatetime. Now I was looking for SQL Statement like I will give from date and to date as parameter it should select date of birth occurring between that date and month.

View 5 Replies View Related

Selecting A Middle Date

May 3, 2006

So I have this query where i need to get the average date of about five different dates... Is there any way to do this or am I screwed. I looked at using the avg function but SQL server 2005 did not like that.

Thanks in advance for any help.

View 3 Replies View Related

Selecting Latest Date

May 8, 2008

Hello all. I ma using the following query to pull back data. The MergeHistory table has a column named DateMerged. I am looking to pull back the one record with the most recent DateMerged. I have managed to get the query as far as below but not sure how to select the most recent one. Can anyone help with this? I was told it may be along the line of SELECT TOP 1 or something?


INSERT INTO @List (IndexID, IndexName, MergeSystem, Status, DateCreated, CreatedBy, DataTag, MergedDate)
SELECT DISTINCT
RT.IndexId,
isnull(dbo.ufn_GetBestIdentifier(RT.IndexId), dbo.ufn_GetBestVirtualIdentifier(RT.IndexId)),
dbo.ufn_GetEntitySystemName(RT.IndexId),
RT.Status,
CONVERT(varchar, RT.DateCreated, 106) as DateCreated,
RT.CreatedBy,
RT.DataTag,
MH.MergedDate
FROM @resulttable AS RT, MergeHistory AS MH
WHERE RT.IndexId = MH.EntityID

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved