Adding Some Rows To A Select

Jul 20, 2005

Hi folks,

I've a sql query problem I was wondering if you all had a quick and
dirty solution for. I've a query:

Select code, value from table_a where date in
(2004) and a_code in ('1000','2000') and b_code in ('01000','02000')

This returns a table that looks like:

A_CODE B_CODE VALUE
------ ------ -----

1000 01000 $500
1000 02000 $750

What I'd like to see is:

A_CODE B_CODE VALUE
------ ------ -----

1000 01000 $500
1000 02000 $750
2000 01000 $0
2000 02000 $0

Any suggestions on how to rewrite my query so the results show A_CODE
2000 with a VALUE of 0 or null?

Thank much in advance!

Marc

View 1 Replies


ADVERTISEMENT

Adding Static Rows

Mar 5, 2008



Hi,

I have a data; descriptions (types of elements in my system) on rows, and results (numeric values) of different branches for each description on columns. I have one entry (one row) for each individual day (so i have year, month and day columns) I prepared a report for this data (using enable drilldown; year --> month --> day --> description and its numeric values on the row) But I have to add new descriptions using my own descriptions, like formulas... My descriptions and my new descriptions made of with old ones, should be listed one under the other

For ex;
new_description = (descr1 + descr2) / descr7

Can I do this on report design step? If so, how?

View 4 Replies View Related

Adding Values Of Rows In Ms Sql 2000

Jun 3, 2006

I am building a website in asp.net 1.1 with vb.net 2003 which will have the standings of the teams in our baseball league.  Below is the database table I have created.
 
ID(int)  home_team (nvarchar)  away_team(nvarchar)  win_teampf(nvarchar) lose_teampf(nvarchar)
1    Elmwood    Murdock    7   22    Louisville     Manley       4   33    Manley        Elmwood    9  8
ID is the primary key.  What I am attempting to do is add each instance of Elmwood from the win column to output the total number of wins from Elmwood and do the same for Elmwood in the losing team to output the total number of losses. The result will look something like this:
Elmwood: 1 Win  1 Loss. .500
Thanks for your reply.
 

View 5 Replies View Related

Problem With Adding And Deleting Rows

Jan 6, 2008

Hi dear users,

I have a crisis situation with my simple database project. Let me introduce You to the topic.

I've created table ZAKLADY in my db:






Code Block

CREATE TABLE ZAKLADY
(ZAKL_ID INT IDENTITY(10,10) CONSTRAINT PK_ZAKLADY PRIMARY KEY,
ZAKL_NAZWA VARCHAR(25),
ZAKL_MIASTO VARCHAR(20),
ZAKL_ULICA VARCHAR(30) );


Then, I've made procedure which adds one row:






Code Block

CREATE PROCEDURE Zakl_AddNewRow
@zakl_nazwa VARCHAR(25),
@zakl_miasto VARCHAR(20),
@zakl_ulica VARCHAR(30)
AS
INSERT INTO Zaklady (Zakl_Nazwa, Zakl_Miasto, Zakl_Ulica)
VALUES (@zakl_nazwa, @zakl_miasto, @zakl_ulica)


Also I've made procedure which deletes the row.





Code Block

CREATE PROCEDURE Zakl_DeleteRow
@zakl_id INT
AS
DELETE Zaklady
WHERE Zakl_ID=@zakl_id

So what's the point of my problem?

If I execute the procedure "Zakl_AddNewRow", I will add a new row to ZAKLADY table. Column ZAKL_ID is added automaticly
because, as You can see, it is declared as INT IDENTITY(10,10). I have added 5 rows so the ZAKL_ID values will be adequately 10,20,30,40,50.
Now I delete the row with ZAKL_ID = 30.
After it I add new row once again.
The result is that the ZAKL_ID value will be 60.

So the number "30" of the identity sequence became unsigned to any ZAKL_ID.
I wanted that new row which was added has ZAKL_ID=30 not 60. The second added row should have ZAKL_ID=60.
Is there any possibility to do this.If yes, What should I change in sql code.

Thank You for all replies

Maciej

View 6 Replies View Related

SSRS Adding Group Rows

Mar 6, 2008



Hello Friends,
I have created a report using SSRS and in that report I am using group rows in one of the matrix. When I tried to display the subtotal of that group row by using the SSRS in-built feature the subtotal column is coming at the last of the matrix columns but I want it at the front .

so it will be like this,

First the total should be displayed then the group members value.

Can anyone help me on this issue.

Thanks & Regards
Shivanandan Gupta

View 7 Replies View Related

Adding A Single Change To All Rows In A Column

Jan 16, 2002

View 1 Replies View Related

Adding A Single Change To All Rows In A Column

Jan 16, 2002

We just changed over our phone system and the new system uses all of the old extensions except it adds a 1 to the beginning of them. I know that there is a relatively simple way to update my phone extension column to show this, but I can't for the life of me remember what I need to do. Any help?

View 2 Replies View Related

SQL Server 2012 :: Adding Certain Rows And Minus Value With A Row

Nov 25, 2014

I got a table where i need to add certain rows and minus the valu with a row.

IDC1C2C3C4C5C6
1551557775
266201452
345222266
441727582
532556951
6022022
7182344142
8

Result in the 8 Row

Sum(id(2,3,4)-sum(id(6,7))

View 2 Replies View Related

Delete Table Or Rows Before Adding New Ones?!?! Help Needed...

Apr 28, 2008

Hi there, I have a simple data flow from OLE DB to OLE DB that writes data from a view into a table. Is it possible to delete the table or the rows within the table before wirting the new data???

Thanks in advance!

View 10 Replies View Related

Select Distinct Rows From Duplicate Rows....

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

Slowly Changing Dimension - Adding New Rows When No Change

Apr 16, 2007

Hi , I am using the Integration Services slowly changing dimension to move data from a SQL Server 2000 database table to a SQL Server 2005 table.

The problem is the package is not tracking changes, it is spending a lot of time doing lookups (i'm guessing this cost it's real slow), but ends up creating new records when there has not been a change.

I'm quite sure the business key is set up correctly (I'm using the PK from the source table).

The database I am transferring from has non Unicode data types (ie varchar and char) and the destination database has Unicode data types (ie nvarchar).

Also some of the fields in the dB are NULL - does this have an effect (ie one null doesn't equal another null)? Or shouldn't that matter?

View 4 Replies View Related

AS 2005 Slowly Changing Dimension - Adding New Rows When No Change

Apr 15, 2007

Hi , I am using the Integration Services slowly changing dimension to move data from a SQL Server 2000 database table to a SQL Server 2005 table.

The other problem is the package is not tracking changes it is spending a lot of time doing lookups (it's slow), but ends up creating new records when there has not been a change.

I'm quite sure the business key is set up correctly (I'm using the PK from the source table).

The database I am transferring from has non Unicode data types (ie varchar and char) and the destination database has Unicode data types (ie nvarchar).

Also some of the fields in the dB are NULL - does this have an effect (ie one null doesn't equal another null)? Or shouldn't that matter?

View 1 Replies View Related

Creating A Table And Adding Rows To Database In Studio Management

Aug 12, 2015

I am trying to use the following Query to create the table Agents and add rows to it.

USE REMAXCLASSIC;
IF OBJECT_ID ('dbo.Agents', 'U') IS NOT NULL
DROP TABLE Agents;
GO
CREATE TABLE Agents

[Code] ....

I get the following error messages:

Msg 102, Level 15, State 1, Line 34 Incorrect syntax near '0.25'
Msg 105, Level 15 mark after the character string ');

View 2 Replies View Related

Adding, Deleting Rows From Visual Basic 2005 Express Edition

May 27, 2007



Hi,



I'm a complete novice concerning SQL Server (Express Edition)

I'm trying to Add or Delete rows froma VB 2005 Express Function or Sub. While the program is running everything is ok. Except when restarted added records are gone and deleted records are back.



Have i missed an option during installation?



Thx,

Steven

View 5 Replies View Related

SELECT * Not Returning Any Rows, But SELECT COL_NAME Does!

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

Transact SQL :: Adding A Column To A Large (100 Million Rows) Table With Default Constraint?

Apr 24, 2013

IF NOT EXISTS (SELECT TOP 1 1 FROM dbo.syscolumns WHERE id = OBJECT_ID(N'dbo.Employee) and name = 'DoNotCall')
BEGIN
ALTER TABLE [dbo].[Employee] ADD [DoNotCall] bit not null Constraint DoNot_Call_Default DEFAULT 0
IF ( @@ERROR <> 0 )
GOTO QuitWithRollback
END

It just takes a LOT of time in SQL Server Management studio. I have to cancel the query and cancelling takes a whole lot time. I am using SQL Server 2008.

View 4 Replies View Related

Adding Variable To SELECT For CURSOR

Oct 13, 2003

I'm trying to build a select statement for a CURSOR where part of the SQL statement is built using a variable.
The following fails to parse:

Declare Cursor1 Cursor
For
'select table_name from ' + @database + '.Information_Schema.Tables Where Table_Type = ''Base Table'' order by Table_Name'
Open cursor1

That doesn't work, I've also tried using an Execute() statement, no luck there either. Any ideas or suggestions are greatly appreciated.

View 7 Replies View Related

Adding Groups In A Select Statement

Jul 8, 2014

The select statement below works fine but just to a limited extend.

There is just one table (prices) with 3 fields (ticker, close, date).

I use this select statement to get monthly returns for 1 ticker.

My question is: can I get this same statement for multiple tickers? I guess I have to group by ticker but I wouldn´t know how to do it.

--Get Monthly Returns As Percentage
WITH PriceMonthly_CTE
AS
(select
row_number() OVER (ORDER BY DATE_) AS Period,

[Code] .....

View 2 Replies View Related

Adding New Column To Group By - Select

Feb 25, 2015

I´m looking to create a select where I sum the daily_return by stock_code, and then I would like to have an additional column containing the most recent "rating" available by date

So if you where to execute the query below, the result would be:

stock1 0.54 3
stock2 0.05 1

Here is what I have so far:

DECLARE @stock_returns TABLE
(
stock_code VARCHAR(10) NOT NULL,
date1 DATE NOT NULL,
daily_return NUMERIC(10, 2) NOT NULL,
rating numeric (6,0) not null);

[Code] .....

View 2 Replies View Related

Dynamically Adding Select Parameters (Filter)

Jul 24, 2007

how do i add parameters like this dynamically? do i need to change the select command? to add the @ID part? 

View 4 Replies View Related

Adding Column Values Together In SQL SELECT Statement

Aug 22, 2007

I have an SQL Select statement that I need to add a column to called SalePrice, the SalePrice column needs to be calculated by adding together the values of 12 columns, then multiplying that value by the value in a another column to calculate margin.  My issue is that I can only get it to add 7 column values together, if I add any more columns to the equation it just returns and null result.  My DB is SQL 2005 Express SP2.  My select statement is below:  SELECT dbo.MFG_DATA_Machines.ID, dbo.MFG_DATA_Machines.MachineName, dbo.MFG_DATA_Parts_CPU.PartDescription AS CPU,
dbo.MFG_DATA_Parts_CPU.PartCost AS CPUCost, dbo.MFG_DATA_Parts_Motherboard.PartDescription AS Motherboard,
dbo.MFG_DATA_Parts_Motherboard.PartCost AS MotherboardCost, dbo.MFG_DATA_Parts_RAM.PartDescription AS RAM,
dbo.MFG_DATA_Parts_RAM.PartCost AS RAMCost, dbo.MFG_DATA_Parts_HDD.PartDescription AS HDD,
dbo.MFG_DATA_Parts_HDD.PartCost AS HDDCost, dbo.MFG_DATA_Parts_OpticalDrive.PartDescription AS OpticalDrive,
dbo.MFG_DATA_Parts_OpticalDrive.PartCost AS OpticalDriveCost, dbo.MFG_DATA_Parts_Video.PartDescription AS Video,
dbo.MFG_DATA_Parts_Video.PartCost AS VideoCost, dbo.MFG_DATA_Parts_OS.PartDescription AS OS, dbo.MFG_DATA_Parts_OS.PartCost AS OSCost,
dbo.MFG_DATA_Parts_Modem.PartDescription AS Modem, dbo.MFG_DATA_Parts_Modem.PartCost AS ModemCost,
dbo.MFG_DATA_Parts_FloppyDrive.PartDescription AS FloppyDrive, dbo.MFG_DATA_Parts_FloppyDrive.PartCost AS FloppyDriveCost,
dbo.MFG_DATA_Parts_CardReader.PartDescription AS CardReader, dbo.MFG_DATA_Parts_CardReader.PartCost AS CardReaderCost,
dbo.MFG_DATA_Parts_PowerSupply.PartDescription AS PowerSupply, dbo.MFG_DATA_Parts_PowerSupply.PartCost AS PowerSupplyCost,
dbo.MFG_DATA_Parts_CaseType.PartDescription AS CaseType, dbo.MFG_DATA_Parts_CaseType.PartCost AS CaseTypeCost,
dbo.MFG_DATA_Machines.Notes, dbo.MFG_DATA_Machines.MarginPercent, dbo.MFG_DATA_Machines.PriceOverride,
(dbo.MFG_DATA_Parts_CPU.PartCost + dbo.MFG_DATA_Parts_Motherboard.PartCost + dbo.MFG_DATA_Parts_RAM.PartCost + dbo.MFG_DATA_Parts_HDD.PartCost
+ dbo.MFG_DATA_Parts_OpticalDrive.PartCost + dbo.MFG_DATA_Parts_Video.PartCost + dbo.MFG_DATA_Parts_OS.PartCost + dbo.MFG_DATA_Parts_Modem.PartCost
+ dbo.MFG_DATA_Parts_FloppyDrive.PartCost + dbo.MFG_DATA_Parts_CardReader.PartCost + dbo.MFG_DATA_Parts_PowerSupply.PartCost + dbo.MFG_DATA_Parts_CaseType.PartCost)
* ((dbo.MFG_DATA_Machines.MarginPercent + 100) / 100) AS SalePrice
FROM dbo.MFG_DATA_Machines LEFT OUTER JOIN
dbo.MFG_DATA_Parts_CaseType ON dbo.MFG_DATA_Machines.CaseType = dbo.MFG_DATA_Parts_CaseType.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_Motherboard ON dbo.MFG_DATA_Machines.Motherboard = dbo.MFG_DATA_Parts_Motherboard.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_Video ON dbo.MFG_DATA_Machines.Video = dbo.MFG_DATA_Parts_Video.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_RAM ON dbo.MFG_DATA_Machines.RAM = dbo.MFG_DATA_Parts_RAM.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_PowerSupply ON dbo.MFG_DATA_Machines.PowerSupply = dbo.MFG_DATA_Parts_PowerSupply.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_OS ON dbo.MFG_DATA_Machines.OS = dbo.MFG_DATA_Parts_OS.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_OpticalDrive ON dbo.MFG_DATA_Machines.OpticalDrive = dbo.MFG_DATA_Parts_OpticalDrive.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_Modem ON dbo.MFG_DATA_Machines.Modem = dbo.MFG_DATA_Parts_Modem.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_HDD ON dbo.MFG_DATA_Machines.HardDisk = dbo.MFG_DATA_Parts_HDD.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_FloppyDrive ON dbo.MFG_DATA_Machines.FloppyDrive = dbo.MFG_DATA_Parts_FloppyDrive.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_CPU ON dbo.MFG_DATA_Machines.CPU = dbo.MFG_DATA_Parts_CPU.ID LEFT OUTER JOIN
dbo.MFG_DATA_Parts_CardReader ON dbo.MFG_DATA_Machines.CardReader = dbo.MFG_DATA_Parts_CardReader.ID  

View 2 Replies View Related

Help: Adding Field In Select SP Causes The Update SP To Crash...

May 25, 2008

All- Please advise how to configure a gridview so that when introducing non-editable fields to the select statement, the edit function doesn't crash with a "Procedure or function (UpdateCommand) has too many arguments specified."
The scenario: Update works find when I  have a gridview based on the following SPs:

SELECT:
1 ALTER PROCEDURE dbo.H2SelectCommand
2 AS
3 SET NOCOUNT ON;
4 SELECT headcount_id, person_id, act_session_id, no_answer
5 FROM headcount
6

 INSERT:

1 ALTER PROCEDURE dbo.H2UpdateCommand
2 (
3 @person_id smallint,
4 @act_session_id smallint,
5 @no_answer bit,
6 @Original_headcount_id smallint,
7 @headcount_id smallint
8 )
9 AS
10 SET NOCOUNT OFF;
11 UPDATE [headcount] SET [person_id] = @person_id, [act_session_id] = @act_session_id, [no_answer] = @no_answer WHERE (([headcount_id] = @headcount_id));
12

HOWEVER, when I alter the select command so that it includes a column (person.person_name) from a parent directory like this:

1 ALTER PROCEDURE dbo.H2SelectCommand
2 AS
3 SET NOCOUNT ON;
4 SELECT headcount_id, person.person_name, headcount.person_id, act_session_id, no_answer
5 FROM headcount
6
7 INNER JOIN person
8 ON headcount.person_id = person.person_id
 
...and then proceed to do an Edit/Update operation, I get the pesky "Procedure or function H2UpdateCommand has too many arguments specified" message.
The only obvious thing I could think to try was to configure the new column in the gridview to be Read Only, but this didn't help. Do I have to alter the Update SP to somehow account for the new field, even though the warning already says that there's too many arguments in it?
Any ideas on how to fix this error would be appreciated!
-Kurt
 
 
 
 

View 3 Replies View Related

Adding Optional Criteria In A Select Proc

Nov 26, 2004

I would like to write 1 proc that can take additional criteria if its sent in. An example is:

select HA.PriceId, HA.VendorPackageId from Criteria HA Inner Join
(
select VendorPackageId from ValidVendorPackages
where Vendor = @VENDOR
and Sitecode = @SITECODE
and PackageType = @PACKAGETYPE
)HB on HA.VendorPackageId = HB.VendorPackageId
and CriteriaId in
(
select CriteriaID from ValidItemCriteria
where Destination = @DESTINATION
and LengthOfStay = @LENGTHOFSTAY
and Ages = @AGE
and ComponentType = @COMPONENTTYPE_1
and ValidItemType = @VALIDITEMTYPE_1
and ItemValue = @ITEMVALUE_1
)


Multiple @COMPONENTTYPE, @VALIDITEMTYPE,@ITEMVALUE can be sent in.
Instead of making multiple procs or copying the proc multiple times with an if statement at the top checking the number of parameters that aren't =''. Is there a way to exectue:

and CriteriaId in
(
select CriteriaID from ValidItemCriteria
where Destination = @DESTINATION
and LengthOfStay = @LENGTHOFSTAY
and Ages = @AGE
and ComponentType = @COMPONENTTYPE_1
and ValidItemType = @VALIDITEMTYPE_1
and ItemValue = @ITEMVALUE_1
)
and CriteriaId in
(
select CriteriaID from ValidItemCriteria
where Destination = @DESTINATION
and LengthOfStay = @LENGTHOFSTAY
and Ages = @AGE
and ComponentType = @COMPONENTTYPE_2
and ValidItemType = @VALIDITEMTYPE_2
and ItemValue = @ITEMVALUE_2
)
and CriteriaId in
(
select CriteriaID from ValidItemCriteria
where Destination = @DESTINATION
and LengthOfStay = @LENGTHOFSTAY
and Ages = @AGE
and ComponentType = @COMPONENTTYPE_3
and ValidItemType = @VALIDITEMTYPE_3
and ItemValue = @ITEMVALUE_3
)

Ignoring the 2nd 2 selects if @COMPONENTTYPE_2, @VALIDITEMTYPE_2,@ITEMVALUE_2 and @COMPONENTTYPE_3, @VALIDITEMTYPE_3,@ITEMVALUE_3 are = ''

Thanks for your help in advance.

View 7 Replies View Related

SQL Server 2014 :: Adding One More Column For SubTotal In Select Statement?

Feb 13, 2014

We have a table with 2 columns 'OrderNo' and 'Amount' as below

ORDERNO | AMOUNT
1D1ZX000 | 9262.5
1D1ZX001 | 9000.0
1D1ZX001 | 9000.0
1D1ZX002 | 10000
1D1ZX003 | 1000
1D1ZX003 | 200.50
1D1ZX003 | 100.50
1D1ZX004 | 500.0
1D1ZX004 | 1000
1D1ZX004 | 2000
1D1ZX004 | 1000

as per my client requirement we need subtotal of 'Amount' group by 'OrderNo'. column so am writing a select statement with WHERE condition and I would like to have another column called SUBTOTAL in the result set (select statement result) with subtotals for that order Number as below

ORDERNO | AMOUNT | SubTotal
1D1ZX000 | 9262.5 | 9262.5
1D1ZX001 | 9000.0 | 18000
1D1ZX001 | 9000.0 | 18000
1D1ZX002 | 10000 | 10000
1D1ZX003 | 1000.0 | 3001
1D1ZX003 | 2000.5 | 3001
1D1ZX003 | 1000.5 | 3001
1D1ZX004 | 500.00 | 4500
1D1ZX004 | 1000.0 | 4500
1D1ZX004 | 2000.0 | 4500
1D1ZX004 | 1000.0 | 4500

View 7 Replies View Related

Select All Rows Except Some Rows

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

I Want To Select All Rows Between 10 And 20 .......

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

Select Last Rows

Feb 13, 2001

How can I SELECT the last rows inserted in a table?

View 2 Replies View Related

Select Rows By One For Each Value

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

Select 2 Or More Rows With Same Id But..

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

Select Last 20 Rows

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

Select Rows With Like

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

Select Rows Where Row Count &> 3

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

Select Distinct Rows

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







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