How To Select Max Amount Rows
Jul 20, 2005
please help to select these rows from these tables my tables are
table1
table1Id groupId table2id price
1 1 1 10
2 1 3 1000
3 1 4 500
4 2 1 5
5 2 3 1000
6 2 2 2000
table2
table2id name
1 hello
2 test
3 test1
4 test2
ok i want to select maximum priced row from table1 grouped by groupid
with table2id and table2.name
my out put is
groupid price table2id table2.name
1 1000 3 test1
2 2000 2 test
if i do :
select groupid,max(table1.price) as price from table1 group by price
this will give me the max priced row from table1
but when i join them with the table2 it gives me all rows
like
Select groupid,max(price) as price,table2id,table2.name from table1
inner join on table2
group by groupid,table2id,table2.name
it gives me all rows cause i had to group by table2.id and table2.name
but i can't take it out cause it give me no aggrigated value error
i can't figure out any other way, please help
SQL Server 2000
thanks
eric
View 2 Replies
ADVERTISEMENT
Oct 10, 2007
TotalSelected.Value = SqlDataSource1.SelectCommand = "SELECT COUNT(*) FROM tblNews";
the reason i am tring to do this is so if i can find out the amount of rows before sqldatasource selects for details view then i can make the sqldataesource select depends on total minus 5 so e.g. if total 200 then - 5 so i can select bottom 195 so it misses top 5 for details view any1 any ideas?
Thanks Andy,
View 5 Replies
View Related
Jul 23, 2005
Hello,I have experienced that some of my tables occupies an extremely large amountof pages but with few rows. An example is a table with 37 rows over 22000pages !. The columns are simple integer and char. I fixed the problem byintroducing a clustered index. Now it only uses 1 page. But can anyoneexplain this behaviour in SQLServer 2000 ?regards Jakob Mathiasen
View 4 Replies
View Related
May 26, 2007
We are running merge replication, SQL Server 2005 Enterprise with SQL Mobile 2005 (Windows Mobile 5) subscribers. Partitions are filtered on HOST_ID.
Ocassionally we experience a situation where a subscriber experiences an unusually long synchronization duration, and upon examining Replication Monitor, it appears that twice the number of rows, or X the number of rows (up to 7 times the number of rows) that should have been inserted are recorded as synchronized for the session: once the normal amount as inserts and once the normal amount as updates. This occurs for all tables in the subscription. This occurs on a first time synchronization to an empty subscriber database where there should be only inserts taking place.
I have examined the snapshot partition folders for these users on the file system and they appear to be identical in size and content as other subscribers. Checking the last partition snapshot job run and other characteristics for the the subscriber in question, everything appears to be the same as other subscribers functioning normally.
The HOST_ID for us is an employee ID used to filter employee specific data. I have seen this happen if the subscriber changes the value for the HOST_ID used in filtering, after the mobile database has already been populated (2 employees attempt to use the same mobile device and database). But, we have seen this happen recently where the HOST_ID was apparantly never changed midstream.
This just started happening recently. The only modification around the same time frame was the implementation of a custom business logic handler/custom conflict resolver that performs like "Latest Wins" but has logic added to update the a last-update datetime column for selected transaction tables at time of synchronization, so that an SSIS job can detect the changed rows for copying incremental database changes to another application database. This all seems to be working perfectly.
Any ideas?
Thanks,
Matt
View 1 Replies
View Related
May 20, 2012
I need to show the total amount of rows in a specific table?
The query is as follows:
As part of the planning process to expand the database that supports Northwind operations, the IT manager would like to know how many rows are currently in specific tables so that he can conduct capacity planning.
The results needed include two columns, TableName( containing all the tables in the database and Rows, which contain the total amount of all the rows per table).
View 4 Replies
View Related
Oct 1, 2014
I have an issue where I have multiple rows of data and I need to reduce a dollar amount by a fixed maximum. I am going to throw some code in here to give a rudimentary idea of the data and what the final result should be.
declare @tbl table
(LineNum int,
Code varchar(2),
Amt money,
MaxAmt money
[Code] ....
I need to run an update so that the result of the following query:
select LineNum, Code, Amt, MaxAmt from
@tblLooks like this:
LineNum Code Amt MaxAmt
----------- ---- --------------------- ---------------------
1 AA 10.00 50.00
2 AA 20.00 50.00
3 AA 20.00 50.00
(3 row(s) affected)
I have tried cursors but got unexpected results or the MaxAmt always defaulted to the original even if I updated it. This seems like a simple problem but I have been banging my head against the wall for 2 days now. I've written some pretty complicated updates with less effort than this and I must have some mental block that is keeping me from figuring this out.
View 3 Replies
View Related
May 25, 2007
Dear all,
I created a package that seems to work fine with a small amount of data. When I run the package however with more data (as in production) the merge join output is limites to 9963 rows, no matter if I change the number of input rows.
Situation as follows.
The package has 2 OLE DB Sources, in which SQL-statements have been defined in order to retrieve the data.
The flow of source 1 is: retrieving source data -> trimming (non-key) columns -> sorting on the key-columns.
The flow of source 2 is: retrieving source data -> deriving 2 new columns -> aggregating the data to the level of source 1 -> sorting on the key columns.
Then both flows are merged and other steps are performed.
If I test with just a couple of rows it works fine. But when I change the where-clause in the data source retrieval, so that the number of rows is for instance 15000 or 150000 the number of rows after the merge join is 9963.
When I run the package in debug-mode the step is colored green, nevertheless an error is displayed:
Error: 0xC0047022 at Data Flow Task, DTS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Merge Join" (4703) failed with error code 0xC0047020. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
To be honest, a few more errormessages appear, but they don't seem related to this issue. The package stops running after some 6000 rows have been written to the destination.
Any help will be greatly appreciated.
Kind regards,
Albert.
View 4 Replies
View Related
Apr 28, 2008
Hello!
I have a problem. I want to know if the time which is needed for creating an index increases proportional to the amount of rows. example: if creating an index on a table which 10.000 rows takes 15 seconds. does creating an index on a table with 20.000 rows take 30 seconds , 40.000 rows 60 seconds and so on...
or does it take longer like 10.000 rows 15 second, 20.000 rows 40 seconds, 40.000 rows 80 seconds.
thx for your help!!
Filipe
View 4 Replies
View Related
Jun 5, 2015
I need to generate a csv file from another csv file, seems to be simple but let's go the trick thing:
Needs to have maximum 1000 lines, if I reach to this, I need to create another csv and fill that new one.
Exemplifying:
I have a csv file called fileA and this has 2000 lines and another csv called fileB with 1500 lines.
I need to loop a folder and get the fileA, create an output called FileAOutput and start to fill that, if I reach to 1000 lines, I need to create a FileAOutput_2 and fill the other 1000 lines...so I'll go to fileB and do the same thing, but in the second case, I'll have 500 lines in the second output.
View 5 Replies
View Related
Jan 17, 2007
I need to convert a date like 08/1/2009 to 0809
I also need to show currency as 100.00 and not 100.0000
How can I do these in a select statement?
SELECT CONVERT(Varchar(20),ExpirationDate,10) AS ExpirationDate, Amount FROM tblPayment
I appreciate any help!
View 5 Replies
View Related
Jan 17, 2008
Ok so we gotSELECT this, that, others FROM some.database WHERE this=@this So in the database the others field is a string that can have up to 200 characters, but on this particular data pull I only want to pull the first 50 characters of the others field. How can I do that? Thanks.
View 4 Replies
View Related
Jul 22, 2015
I have a routine that generates an HTML email and sends it just fine, but one of the columns ends up with 4 decimal places for a column datatype of money. How can I get the script to output only 2 decimal places for the amount column from the select statement?
Here's the script:
declare @tableHTML nvarchar(max) ;
set @tableHTML =
N'<h1>Revenue Report</h1>' +
N'<table border="1">' +
N'<tr><th>Amount</th><th>Index</th><th>CompObj</th><th>Rev Type</th><th>Program</th>'+
CAST ((SELECT td=SUM(dbo.tblAllocations.Amount),'',
[code]....
View 2 Replies
View Related
Mar 18, 2008
I'm creating a temporary table in a Sql 2005 stored procedure that contains the transaction amount entered in a period <= the period the user enters.
I can return that amount in my result set. But I also need to separate out by account the amounts just in the period = the period the user enters. There can be many entries or no entries in any period. I populate the temporary table this way:
SELECT
t.gl7accountsid,
a.accountnumber,
a.description,
a.category,
t.POSTDATE,
t.poststatus,
t.TRANSACTIONTYPE,
t.AMOUNT,
case
when t.transactiontype=2 then amount * (-1)
else amount
end as transamount,
t.ENCUMBRANCESTATUS,
t.gl7fiscalperiodsid
FROM
UrsinusCollege.dbo.gl7accounts a
join
ursinuscollege.dbo.gl7transactions t on
a.gl7accountsid=t.gl7accountsid
where
(t.gl7fiscalperiodsid >= 97
And
t.gl7fiscalperiodsid<=@FiscalPeriod_identifier)
And poststatus in (2,3)
and left(a.accountnumber,5) between '2-110' and '2-999'
And right(a.accountnumber,4) > 7149
And not(right(a.accountnumber,4)) in ('7171','7897')
order by a.accountnumber
Later I create a temporary table that contains budget information. I join these 2 temporary tables to produce my result set. But I don't know how to get the information for just one period. For example, if the user enters 99 as the FiscalPeriod_identifier, I need a separate field that contains only those amounts(if any) that were entered for each account in Period 99.
Can anyone help? It may be that I am not seeing the forest for the trees, but I can't figure it out.
Thanks very much.
Sue
View 6 Replies
View Related
Nov 2, 2006
Hello
Im searching for a solution to set all matrix row or cell the same height.
it schoud looks like this example:
This is a simple matrix
test a
text b
text c
text d
text e
text f
text g
This is a matrix with all the same row-height.
test a
text b
.
text c
.
.
text d
text e
text f
text g
.
.
Thx you a lot
View 3 Replies
View Related
Nov 28, 2007
Dear Gurus,I have table with following entriesTable name = CustomerName Weight------------ -----------Sanjeev 85Sanjeev 75Rajeev 80Rajeev 45Sandy 35Sandy 30Harry 15Harry 45I need a output as followName Weight------------ -----------Sanjeev 85Rajeev 80Sandy 30Harry 45ORName Weight------------ -----------Sanjeev 75Rajeev 45Sandy 35Harry 15i.e. only distinct Name should display with only one value of Weight.I tried with 'group by' on Name column but it shows me all rows.Could anyone help me for above.Thanking in Advance.RegardsSanjeevJoin Bytes!
View 4 Replies
View Related
Aug 10, 2006
Hi all,
I have a table named Prescription that consists of attributes like PatientId, MedicineCode, MedicineName, Prices of different drugs, quantity of different drugs(e.g 1,2,3,10), date .
I would like to get a summary of the total number and amount of different drugs in a specific period, the total amount of each type of drug.
I kindly request for help.
Thanx in advance.
Ronnie
View 4 Replies
View Related
Jul 20, 2005
I have a table which is returning inconsistent results when I queryit!In query analyzer:If I do "SELECT * FROM TABLE_NAME" I get no rows returned.If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.In Enterprise manager:If I do "return all rows" I get 4 rows returned, and the SQL is listedas being "SELECT * FROM dbo.TABLE_NAME".I've tried adding the "dbo." before my table name in QA, but it seemsto make no difference.I'm using SQL Server 2000, which is apparently 8.00534.Can anyone help me, or give me ideas about what to check?Thanks,Rowland.
View 9 Replies
View Related
Feb 3, 2006
Hi all,
Is it possible to say something like
INSERT INTO Book
Book.* EXCEPT (a,c,d)
Something like WITHOUT
DESELECT
EXCLUDING
LESS
Thanks
View 4 Replies
View Related
Feb 15, 2007
I want to select all rows between 10 and 20 from aview
how can I do this?
View 3 Replies
View Related
Feb 13, 2001
How can I SELECT the last rows inserted in a table?
View 2 Replies
View Related
Oct 12, 2004
Tell me please how to select from a table only rows with different value of one of fields (n_pr field). But I need also to select some other fields where the values can be different for one n_pr field's value and select only first value of them. For getting list of n_pr field's values I can use derived table of query with DISTINCT operator but I don't know how to join with other fields of the table to get only one row for each value of joinning field n_pr. I am using SQL Server 2000 and this DBMS can use TOP operator to select only one row but all the ways I've tryed affect all the query and I get one row at all instead of one for each n_pr field's value. Also I need in this query to connect one more table. So for efficiency it better to do it in one query or in one stored procedure that return a recodset as it needs.
View 1 Replies
View Related
Jun 24, 2008
I want to select rows that have been amended or deleted and want to use the amend date as the condition.all amended rows have a flag of 1 and deleted ones have a flag of 2
i.e
select * from table
where log_changed > '2008-06-23' and log_changed < '2008-06-24'
will display all the rows that were amanded on the 2008-6-23 and with a flag of 1 or 2
but i also want the query to return the original row that was amended and has a flag of 0.the original row has a null log_changed field.
the rows that must be returned must be the ones amended or deleted ones on a specific date but with the original ones as well.
any ideas please
In god we trust,everything else we test.
View 9 Replies
View Related
Jun 6, 2007
I am very new to db and sql. I have a populated table and would like to run a query that brings up the last 20 rows. Here is what I have now...do I need a WHERE statement?
SELECT
d.cache_diff AS $<scachediff>,
d.cache_name AS $<scachename>,
d.cache_type AS $<scachetype>,
d.cache_last_found AS $<cachelastfound>,
d.cache_id AS $<cache_view_link>,
d.cache_id AS $<log_find_link>
FROM geocaches d
View 5 Replies
View Related
Apr 28, 2008
Is it possible to write a stored procedure to select records that start with a passed string without using dynamic sql.
E.g.
SELECT EmpName FROM Employee WHERE EmpName LIKE 'John%'
How does write the above query as a stored procedure (not dynamic sql). The 'John' should be received as argument to the procedure.
View 3 Replies
View Related
Jan 4, 2007
I have a view that I want to find all the rows that have a matching itemid and have more than 3 rows in them and group them by the itemid.
I am not quite sure how to do this.
Any ideas?
~mike~
View 5 Replies
View Related
Mar 19, 2004
Hi,
I'm having a little bit of trouble trying to figure out how to do this query, right now I have:
SELECT I.AppItemId, P.ProductID, P.PartNum, P.Relist, I.AppUserId
FROM ProductsToRelist I join Products P on P.ProductID = I.AppSKU
WHERE P.Relist = 1 and I.AppStatus = 5 and Not I.AppItemId is Null
and it returns something like this:
AppItemId ProductID PartNum Relist AppUserId
2786 -32730 SELECT_OOS11
2787 -32729 SELECT12
2788 -32727 SELECT_OOS11
4269 -30987 SELECT_OOS12
1665 -30987 SELECT_OOS11
2433 -30987 SELECT_OOS11
4272 -30984 SELECT11
2436 -30984 SELECT11
2793 -32708 SELECT11
But I only it want it to return 1 record for each ProductID like so:
AppItemId ProductID PartNum Relist AppUserId
2786 -32730 SELECT_OOS11
2787 -32729 SELECT12
2788 -32727 SELECT_OOS11
4269 -30987 SELECT_OOS12
4272 -30984 SELECT11
2793 -32708 SELECT11
ProductID is the primary key for the Products table, and a product can be in the ProductsToRelist table many times but each row would have a unique AppItemId. I know that I need to use Distinct or a different kind of join, but I'm not sure which. How would you suggest to do this?
Thanks
View 4 Replies
View Related
Jun 5, 2006
I have the following tablecolumns: [col1], [col2],[col3] and [NAME].I want to select the name column for each row where [col1]='07'.The problem is that there are several rows where [col1] contains '07' and also the name is the same. [col2] and [col3] contain different data for these double rows...however, I cant use the [col1] and [col2] values in my query because I dont know what values they contain beforehand.So now, when I execute my query and add the DISTINCT key I still get all the double rows!I hope this explains my problem, help is really appreciated...ow, btw: deleting the double rows is not an option....
View 4 Replies
View Related
Mar 21, 2001
Hello,
What is the command to select rows between RowNum25 and RowNum30 in a Sql table?
Aditya
View 1 Replies
View Related
Oct 15, 2004
heyas,
i wanna know how can i select only entries with at least 2 rows?
What i mean is that i want to make a select * from table1 where columnA = 'Something' order by columnB
but addicionally i want it to return only register that happen at least 2 times for columnB
thanks in advance!
View 2 Replies
View Related
Dec 20, 2005
Hi Friends...
I have one table , suppose TableA which contains following columns..
I want to select records from this table where time difference is more than 2 min. (tec_insert_date) This means first record time and second one, then second one and third one..and so on..
How to select these records...pls give me some sql query...
thanks in advance
tec_number tec_insert_date tec_description
----------- ------------------------------------------------------ --------113909 2005-12-19 18:59:01.920 Description
113910 2005-12-19 18:59:02.043 Description
113911 2005-12-19 18:59:02.060 Description
113912 2005-12-19 18:59:02.060 Description
113913 2005-12-19 18:59:02.090 Description
113914 2005-12-19 18:59:02.090 Description
113915 2005-12-19 18:59:02.263 Description
113916 2005-12-19 18:59:02.437 Description
113917 2005-12-19 19:00:34.703 Description
113918 2005-12-19 19:00:34.720 Description
113919 2005-12-19 19:00:34.937 Description
113920 2005-12-19 19:00:35.607 Description
113921 2005-12-19 19:00:35.607 Description
113922 2005-12-19 19:00:35.840 Description
113923 2005-12-19 19:00:35.903 Description
113924 2005-12-19 19:00:36.200 Description
113925 2005-12-19 19:00:36.200 Description
113926 2005-12-19 19:00:36.217 Description
113927 2005-12-19 19:00:36.217 Description
113928 2005-12-19 19:00:36.217 Description
113929 2005-12-19 19:00:36.230 Description
113930 2005-12-19 19:00:36.230 Description
113931 2005-12-19 19:00:36.230 Description
113932 2005-12-19 19:00:36.230 Description
113933 2005-12-19 19:00:36.323 Description
113934 2005-12-19 19:00:36.450 Description
113935 2005-12-19 19:00:38.863 Description
113936 2005-12-19 19:00:38.943 Description
113937 2005-12-19 19:00:38.943 Description
113938 2005-12-19 19:00:39.100 Description
113939 2005-12-19 19:00:39.147 Description
113940 2005-12-19 19:00:39.300 Description
113941 2005-12-19 19:00:40.920 Description
113942 2005-12-19 19:01:23.363 Description
113943 2005-12-19 19:03:03.533 Description
113944 2005-12-19 19:03:08.197 Description
113945 2005-12-19 19:03:12.853 Description
113946 2005-12-19 19:03:14.087 Description
113947 2005-12-19 19:04:40.730 Description
113948 2005-12-19 19:04:44.843 Description
113949 2005-12-19 19:04:51.030 Description
113950 2005-12-19 19:04:56.313 Description
113951 2005-12-19 19:04:58.950 Description
113952 2005-12-19 19:09:19.950 Description
113953 2005-12-19 19:09:21.277 Description
113954 2005-12-19 19:09:21.340 Description
113955 2005-12-19 19:09:24.397 Description
113956 2005-12-19 19:09:35.660 Description
113957 2005-12-19 19:09:46.480 Description
113958 2005-12-19 19:09:47.790 Description
113959 2005-12-19 19:10:23.713 Description
113960 2005-12-19 19:10:23.980 Description
113961 2005-12-19 19:11:02.307 Description
113962 2005-12-19 19:11:52.040 Description
113963 2005-12-19 19:12:31.800 Description
113964 2005-12-19 19:12:31.940 Description
113965 2005-12-19 19:12:31.940 Description
113966 2005-12-19 19:13:10.500 Description
113967 2005-12-19 19:13:10.500 Description
113968 2005-12-19 19:13:50.697 Description
113969 2005-12-19 19:13:50.697 Description
113970 2005-12-19 19:13:50.743 Description
113971 2005-12-19 19:13:50.870 Description
113972 2005-12-19 19:13:50.883 Description
113973 2005-12-19 19:14:09.290 Description
113974 2005-12-19 19:14:47.680 Description
113975 2005-12-19 19:14:47.693 Description
113976 2005-12-19 19:14:48.630 Description
113977 2005-12-19 19:14:48.630 Description
113978 2005-12-19 19:14:49.127 Description
113979 2005-12-19 19:14:49.127 Description
113980 2005-12-19 19:14:49.160 Description
113981 2005-12-19 19:14:49.300 Description
113982 2005-12-19 19:14:49.313 Description
113983 2005-12-19 19:15:07.287 Description
113984 2005-12-19 19:15:07.783 Description
113985 2005-12-19 19:21:43.093 Description
113986 2005-12-19 19:22:01.920 Description
113987 2005-12-19 19:22:01.920 Description
113988 2005-12-19 19:22:20.780 Description
113989 2005-12-19 19:22:38.547 Description
113990 2005-12-19 19:22:38.547 Description
113991 2005-12-19 19:22:39.340 Description
113992 2005-12-19 19:22:39.340 Description
113993 2005-12-19 19:22:40.263 Description
113994 2005-12-19 19:22:41.010 Description
113995 2005-12-19 19:22:41.867 Description
View 3 Replies
View Related
Feb 11, 2004
I get a tabseparated textfile with data every friday. Faulty rows are to be returned to the source.
Double rows are considered a fault. How do I select all double rows?
I join the data later on with four columns so if these columns are alike the rows are considered identical even if other columns are not. Ie:
A, B, C, D, 12, 34, 48, 76
A, B, C, D, 23, 45, 56, 99
These two rows are considered alike since I join on A+B+C+D.
I'd like to select ALL double rows and insert them into a separate table that I can return to the source. Does anyone have an idea how to do this?
View 10 Replies
View Related
Jul 25, 2014
I am trying to build a SQL select query, but am struggling a little bit.I have a table with multiple inventory transactions, each with an ID and weight.
For example:
proc_packxacts
--------------
ID SysProg Weight
210359 271 986
210359 238 985
210359 61 984
210359 5 983
954679 271 1000
354852 271 568
354852 238 523
354852 59 521
354852 5 520
What I want to do is write a SQL query that returns records where there is a transaction for SysProg = 238, but return the weights for some of the other transactions in columns on the same row.Basically, from the above data set, what I would like to return is:
ID Weight (271) Weight (238) Weight (61 or 59)
210359 986 985 984
354852 568 523 521
How to start this?
View 2 Replies
View Related
Feb 5, 2008
Hi!
I am beginner on using SQL.
How can I select the repeated rows (five or more times) on a table which have the same ID's but different updated date. I do not need to group all the rows with the same ID,s but rows which are repeated many times according to the required reports needed.
Below are some information regarding tables and views:
VIEW name= dbo.tblCCInvoicesH
COLUMN ID= ConsumerID
COLUMN DATE= ReadingDate
Thank you in advance...
meti
View 1 Replies
View Related