How To Get The 2nd The 2nd Record AND DISPLAY IN SINGLE ROW ?

Apr 18, 2006

Can you please assist me on how to get the 2nd record in case there are

3 or more records of an employee, the query below gets the MAX and MIN
BasicSalary. However, my MIN Basic Salary is wrong because I should get

the Basic Salary Prior to the 1st Record (DESC)in case there are 3 or
more records and not the last Basic Salary of the Last Record.


How to GET the 2nd Row of Record in Case that There are 3 or more
records IN A SINGLE ROW ???


---------------------------------------------------------------------------*-----



This query gets the Max and Min Basic Salary on a certain Date Range.
In case there are 5 records of an employee on certain date range how
can I get the record before the Max and would reflect as my OLDBASIC,
if I use TOP2 DESC it will display 2 records. I only need one record
which should be the Basic Salary before the 1st record on a DESC order.

Please add the solution to my 2nd Select Statement which get the
OLDBASIC salary Thanks ...


SELECT TOP 100 PERCENT E.EmployeeNo, E.LastName, E.FirstName,
E.SectionCode, E.Department, E.DateHired, E.Remarks,


(SELECT TOP 1 ([BasicSalary])
FROM empsalaries AS T14
WHERE T14.employeeno = E.employeeno AND startdate BETWEEN @FromDate AND

@ToDate
ORDER BY startdate DESC) AS NEWBASIC,


******************************* BELOW I SHOULD ALWAYS GET THE BASIC
SALARY PRIOR TO THE 1ST RECORD AND IN A SINGLE ROW ???


(SELECT TOP 1 ([BasicSalary]) (
FROM empsalaries AS T14
WHERE T14.employeeno = E.employeeno AND startdate BETWEEN @FromDate AND

@ToDate
ORDER BY startdate ASC) AS OLDBASIC


FROM dbo.Employees E
WHERE CONVERT(VARCHAR(10),E.DateHired, 101) BETWEEN @FromDate AND
@ToDate
ORDER BY E.LastName

View 2 Replies


ADVERTISEMENT

Display 20 Rows At Single Time

Sep 25, 2015

The stored procedure takes ~ 10 seconds every call. The execution plan is Index seek or clustered index scan almost everywhere . No table spools or lazy loads or key lookups. Cannot share the code or execution plan due to company rules and regulations.Issue is that i am dealing with result set of around 50,000 records . Out of these i have to return 20 records at a single time (which is also customizable i.e 40 / 60/ 150 records in a page). Application cannot handle all 50k records so i have to return 20 records for every stored procedure call.

The result set changes as per the start date and end date which i recieve as parameters. In application there are few Column filters namely- Country(around 50 countries), Outcome(around 6 to 10 values ) . These filters will values in drop down( as excel ) depending on the distinct values in that columns. These filters will be populated on every page, if no filter value is selected.Issue is if user does sorting or filtering any records , this stored procedure is called and every time i have to deal with ~50000 records.

Current Code :
Step 1 ) Get the required result set in temp table .
Step 2) Compute the results on some business rules . (Outcome and SharesAvailable calculation - see attachment)
Step 3) populate filter Columns (Country,Outcome) these values will be comma seperated.
Step 4) Dynamic query to get required result set i.e if user wants only 10 records in single page then TOP 10 . Sorting can be applied on any column mentioned in screenshot.

View 9 Replies View Related

How To Display Many Rows Data To A Single Row.

Mar 14, 2008

I have a table with only one column as

Emp_Name
A
B
C
D
E

I want to display this data as

Emp_Name
A, B, C, D, E

Is this possible? I am using SQL server 2005.
Any help is appreciated.

Regards,
Vinesh

View 2 Replies View Related

How To Display Multiple Rows Of A Table In Single Row

Dec 15, 2007

DECLARE @emp VARCHAR(1024) declare @emp1 varchar(1024)declare @emp2 varchar(1024)SELECT @emp1 = COALESCE(@emp1 + ',', '') + cast(eid as varchar(10)),@emp = COALESCE(@emp + ',', '') + ename ,@emp2 = COALESCE(@emp2 + ',', '') + desigFROM emp SELECT eid=@emp1,ename = @emp,desig=@emp2 

View 1 Replies View Related

Display Each Of The Record

Jul 25, 2005

I want to know how to display only each of it where in my database for example the ProductItem got a lot of value of '1000' in it. i only want it to display once.

ProductItem | Name
1000 | ABC
1000 | DEF
1000 | HIJ
2000 | KLM
3000 | NOP

I want in my dropdownlistbox only display 1000, 2000, 3000.
I using the 'Select ProductItem from Product' for sure it will display 1000,1000,1000,2000,3000. So to filter it.

Thanks

View 7 Replies View Related

Display Record Of The Day

May 22, 2008

Hi Guys,

How do I display an item in a day? This is a featured product of the day. This will change everyday. I can do this in classic ASP but not in stored procedure.

Table:
This is just to give you an idea of the table
ID | ProductName | DatePosted
----------------------------------------
1 | item1 | 5/1/2008
2 | item2 | 1/2/2008
3 | item3 | 6/2/2007

and so on...

Can someone please help me?

Thanks in advanced.

View 12 Replies View Related

Display Single Number Using ObjectDataSource Scalar Function

Mar 10, 2008

I wrote a Scalar UDF in SQL2005 that returns an integer.  I want to be able to display this integer in a ASP.Net 2.0 web page.  I typically use a DAL for all data so I added an ObjectDataSource as a Qeury that contains only the UDF.  How do I easily display the value in a Label Control or?
I have tried to use a Repeater with a label, a Formview with a Label, all to no avail.  Any suggestions?

View 12 Replies View Related

Select And Display Only One Record

Sep 18, 2013

I have view with Patients name and Appointment table where I save those patients. In form I have 2 comboboxes. For PatientComboBox source is store procedure based on Patient view. For PatientAppintmentComboBox I would like to create store procedure.

How to create store procedure to display only one PatierntName record in PatientAppointmentComboBox if Patient_Id selected from PatientComboBox exist or not exist in Appointment?

View 3 Replies View Related

Reporting Services :: Display Different Data In Cells In A Single Cell?

Oct 30, 2015

i hav four cells that display

startdate            | %completed|    taskname       | indicator
[startdate value]|[%completed]|[taskname value]|[indicatorfield value]

task name and indicator are grouped by years and months

i want all these in a single cell with a separator.

View 6 Replies View Related

Display 2 Record Each From 2 Table In Datagrid

Jul 21, 2005

This is my case. I want in my datagrid to display first record from table A and second record from table B. This is because i need to display a price in the column where it will have current price and history price, therefore the first row will be current price and second row will be history price.

This is the output that i trying to do.

Item | Price
-------|---------
A | 2.50 --------> Table A
A | 1.50 --------> Table B

Please let me know if my explanation is not details enough.

Thanks

View 2 Replies View Related

T-SQL (SS2K8) :: Display Record Using Group By?

Aug 3, 2015

I would like to display all the products with maximum SeqNo from the table below:

TABLE
ProductIDSeqNoBalance
111215
11135
111420
111510
12115
1212100
121325
121445

OUTPUT

ProductIDSeqNoBalance
111510
121445

View 3 Replies View Related

Display Last Updated Record By A User

Mar 30, 2008

I would like to show when leads updated last their records in database. An automated report that tells me when the last date was that the leads updated an entry, only 1 entry per lead.

select Lead,LastUpdated from dbo.KPITbl

I have a table with data that looks like this:

Lead LastUpdated
----------- -----------------------
JOHN SMITH 2008-03-26 08:45:00
JOHN SMITH 2008-03-20 09:33:00
MEG RYAN 2008-02-21 16:16:00
JOHN SMITH 2008-02-21 16:19:00
MEG RYAN 2008-02-21 16:22:00
JOHN SMITH 2008-03-28 16:10:00
JOHN SMITH 2008-03-28 08:49:00
JOHN SMITH 2008-03-23 19:23:00
MARK MCRAE 2008-03-27 03:12:00
MARK MCRAE 2008-03-26 08:48:00
MARK MCRAE 2008-03-26 08:46:00
JOHN SMITH 2008-03-26 08:47:00
JOHN SMITH 2008-03-26 08:48:00
ALLAN WHITE 2008-03-26 08:43:00
ALLAN WHITE 2008-03-26 08:40:00
JOHN SMITH 2008-03-26 08:48:00


Thank you appreciate it.

View 2 Replies View Related

How Do I Display Current SQL Server Record Number

Mar 21, 2008

Do anybody know how can I find or display to the current SQL server 2005 record number (eg. 10 of 1600) on a VB 2005 form label. The BindingNavigator on the form has been deleted. Thanks.

View 6 Replies View Related

Can't Delete Single Record? HELP!

May 28, 2004

OK,

This one is driving me nuts. I've issued a very simple statement to delete a single row from a table. It appears that when I execute it in SQL Query Analyzer the CPUTime spikes and holds one of the CPUs on the box pegged at 100%. I've let this thing run for over a day, and it's not deleting the one damn record. Any thoughts? :confused: :confused: Here's the command I'm executing:

DELETE FROM Invoices WHERE InvoiceID = 153345

Running SELECT * FROM Invoices WHERE InvoiceID = 153345 returns only a single record as it should. InvoiceID is the PK in this table. Any and all help is greatly appreciated. I've rebooted the server, but to no avail. Same thing happens after a reboot.

TIA

View 12 Replies View Related

Single Record / Row Locking

Aug 16, 2007

From SQL Server Books Online, there is a topic: Concurrency Effects, and did mention the following side effects:

- Lost updates.
- Uncommitted dependency (dirty read).
- Inconsistent analysis (nonrepeatable read).
- Phantom reads.

Can someone please tell me which type of Isolation Levels in the Database Engine to avoid the above side effects respectively.

For Record Locking issue:
Example, two editors make an electronic copy of the same document. Each editor changes the copy independently and then saves the changed copy thereby overwriting the original document. The editor who saves the changed copy last overwrites the changes made by the other editor.
This problem could be avoided if one editor could not access the file until the other editor had finished and committed the transaction.

For the above example, is it possible to do like this way:
Editor 1: SELECT and Lock a record
Editor 2: Before SELECT the record, check for the record whether it is locked or not. If it is not lock, then the record can be selected

Please advise.

Thanks.


View 2 Replies View Related

SQL Server 2012 :: SELECT Query - Cursor To Display Result In Single Transaction

May 25, 2015

Here the SELECT query is fetching the records corresponding to ITEM_DESCRIPTION in 5 separate transactions. How to change the cursor to display the 5 records in at a time in single transactions.

CREATE TABLE #ITEMS (ITEM_ID uniqueidentifier NOT NULL, ITEM_DESCRIPTION VARCHAR(250) NOT NULL)INSERT INTO #ITEMSVALUES(NEWID(), 'This is a wonderful car'),(NEWID(), 'This is a fast bike'),(NEWID(), 'This is a expensive aeroplane'),(NEWID(), 'This is a cheap bicycle'),(NEWID(), 'This is a dream holiday')
---
DECLARE @ITEM_ID uniqueidentifier
DECLARE ITEM_CURSOR CURSOR

[Code] ....

View 1 Replies View Related

To Display An Alert Message While Inserting A Duplicate Record

Dec 21, 2005

I am duplicating a record from my asp.net page in to the database. When i click on save I am getting the following error message
Violation of PRIMARY KEY constraint 'PK_clientinfo'. Cannot insert duplicate key in object 'clientinfo'. The statement has been terminated.
The above message i am getting since i have tried to duplicate the clientname field of my table which is set as the primary key.
What i want is instead of this message in the browser i need to display an alert saying "the clientname entered already exists" by checking the value from the database.
Here is my code. pls modify it to achieve the said problem
if(Page.IsValid==true)    {           conn.Open();     SqlCommand cmd = new SqlCommand("insert into clientinfo (client_name, address) values ('"+txtclientname.Text+"', '"+txtaddress.Text+"')", conn);     cmd.ExecuteNonQuery();     conn.Close();     BindData();     txtclear();      System.Web.HttpContext.Current.Response.Write("<script>alert('New Record Added!');</script>");     Response.Redirect("Clientinfo.aspx");    }

View 1 Replies View Related

Stopping A Single Record From Being Deleted

Sep 26, 2006

 I am using a drop down list box to select values from an SQL 2000 DB.  I have put a record into the table which says"...Select Item"I used the dots so that It will apear at the top of the list and therefore display at startup.  I also have a gridview to allow users to edit and delete from the same table.I am worried that a user may accidently delete the "...Select Item" row from the table.Can anyone think of a way round this?  Is it possible with SQL Server 2000 to stop a single record from being deleted?Any help would be most appreciated.ThanksPaul     

View 4 Replies View Related

Returning One Single Record Rather Than Multiples

Feb 12, 2007

HiIs it possible to return the results of a query so that instead ofhaving say 10 rows its concatenated, egMy query returns 'M' 10 times, can this be returned as 'M M M M M M MM M M'?ThanksLee

View 3 Replies View Related

Get Value Of A Single Record Instead Of Aggregated Value With GROUP BY

Oct 12, 2007

How to get


Code Block

a record value instead of aggregated value with GROUP BY?

Assume that I have a PRODUCT_COMMENT table defined as below. It logs
the multiple comments for products. A product may have multiple
comments logged at different time.





Code Block

CREATE TABLE [dbo].[PRODUCT_COMMENT](
[COMMENT_ID] [int] IDENTITY(1,1) NOT NULL,
[PRODUCT_ID] [int] NOT NULL,
[COMMENT] [nvarchar](50) NULL,
[UPDATED_ON] [datetime] NOT NULL,
CONSTRAINT [PK_PRODUCT_COMMENT] PRIMARY KEY CLUSTERED
(
[COMMENT_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[PRODUCT_COMMENT] WITH CHECK ADD CONSTRAINT
[FK_PRODUCT_COMMENT_PRODUCT] FOREIGN KEY([PRODUCT_ID])
REFERENCES [dbo].[PRODUCT] ([PRODUCT_ID])
GO
ALTER TABLE [dbo].[PRODUCT_COMMENT] CHECK CONSTRAINT
[FK_PRODUCT_COMMENT_PRODUCT]

I would like to use the following SQL statement to get the latest
comments for all products.







Code Block

SELECT PRODUCT_ID, COMMENT, UPDATED_ON
FROM PRODUCT_COMMENT
GROUP BY PRODUCT_ID
HAVING UPDATED_ON = MAX(UPDATED_ON)



But this leads to the following error:




Code Block

Column 'PRODUCT_COMMENT.UPDATED_ON' is invalid in the HAVING clause
because it is not contained in either an aggregate function or the
GROUP BY clause.



Is there a way to do that?

Thanks!

View 5 Replies View Related

Convert Single Record To Table

Sep 20, 2007

Hi all!

I have imported a table into SQL Server from a legacy program. Each record has a repeating sequence of similar fields. (Ex. Accnt1, Assesed1, Paid1, Accnt2, Assesed2, Paid2, etc.) I would like to take a single record and put data from these fields into a table that has the columns Accnt, Assesed, and Paid. I am doing this for easier use in a program I am developing in VB 2005. Can this be done in SQL or do I need to have help from some VB code? If it's possible, what might the SQL look like?

Thanks.

View 3 Replies View Related

SELECT Query Syntax To Display Only The Top Record For Duplicate Records

Oct 6, 2005

Good day!

I just can't figure out how I can display only the top record for the duplicate records in my table.

Example:

Table1
Code Date
01 10/1/05
01 10/2/05
01 10/3/05
02 9/9/05
02 9/9/05
02 9/10/05

My desired result would be:
Table1
Code Date
01 10/1/05
02 9/9/05

Thanks.

View 12 Replies View Related

Reporting Services :: Report Builder 3.0 - Display Next Record / Value In Next Column On Same Row

Nov 17, 2015

For my report I am trying to display images that are pulled from a database. Images are from separate records. I have the records I need in a dataset and now I want to set a Table Cell value to the field corresponding to the image. However, the next images/(records) are displayed on the next row (as expected i guess). How do I set the the records/values to be displayed across a single row?

What I have:
image1|
image2|
image3|

What i want: 
image1|image2|image3|etc...

View 3 Replies View Related

How To Retriece Single Record In Database By Using SqlDataSource???

Jun 19, 2007

Is me again,and now i facing problem to retrieve a single record from the database.
here is my code:
 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim user As String        user = TextBox1.Text        Dim varpassword        Dim mydata As SqlDataSource
        mydata.SelectCommand = "Select * from tbluser where uLogin = '" & user & "'"        varpassword = mydata.SelectCommand.uPassword
    End SubEnd Class
 
but i get the error : 'uPassword' is not a member of 'String'
i wan to retrieve the password of that user,can anyone help me?
thanks

View 3 Replies View Related

Single Statement To Delete Record Into More Tables

Aug 6, 2004

Hi ,

I little question for you ... is it possibile to write a SQL statement to delete records in several tables at the same time?

For example if I've two tables involved by join

DELETE <...> from Customers A
INNER JOIN CustomerProperties B ON A.CustomerID=B.CustomerID

I Must use two statement to remove records from both the tables?

Thx

View 3 Replies View Related

SP Return Multiple Records For A Single Record

May 3, 2007

I have two tables
TermID, Term
1--- Abc
2--- Test
4--- Tunic

and
TermID, RelatedTermID
1 --- 2
1--- 4
2--- 4

I need to get back something like this

TermID, Term, RelatedTermsInformation
1--- test--- test,tunic#1,4


that above was my solution, get the relatedterms information and comma separate, and then put a # and get all the ids comma separate them and then put the in one field. then I can later parse it in the client

this does not seem like a very good solution ( or is it?)
If posible it would be nice to get something like this

TermID, Term, RelatedTermsInformation
1 test RelatedTermsTwoDimentionalArray

but I am not sure how this idea could be implemented using the capabilities of SQL.

my other option is have the client make one call to the database to get the terms and then lots of another calls to get the relatedTerms, but that will mean one trip to the DB for the list term, and one call for every single term found.

any ideas in how to make this better ?

View 8 Replies View Related

Combine Multiple Rows Into Single SQL Record

Jan 28, 2008

Hello:

I have the following table. There are eight section IDs in all. I want to return a single row for each product with the various section results that I have information on.

productID SectionID statusID
10 1 0
10 2 1
10 3 2
10 4 1
10 5 3
10 6 1
11 1 0
11 2 1
11 3 2
11 7 3
11 8 3

Need to return two rows with the respective values for each section.

productID section1 section2 section3 section4 section5 section6 section7 section8
10 0 1 2 1 3 1
11 0 1 2 3 3

Any information or if you can point me in the right direction would be appreciated.

Thanks

View 4 Replies View Related

Config Table - Single Record For All Packages

May 2, 2008

Is there any way to use a single record (Which had Connection String) for all my packages in the project ?

I don't want to have multiple connection informations for each of the packages (Based on Configuration Filter)

View 3 Replies View Related

Concatenate Values From Same Column But Different Record In Single Row

Mar 26, 2008

Hi, I have a difficult case that I need to solve. I will try to be the very clear explaining my problem:


I have a sql query which brings me many records.
This records have a column in common which have the same value (COL1)

There is a second column (COL2) which has different values bewteen these records.
I need to concatenate values from the second column in records with same value in COL1. And I need only one record of the ones that have the same values. If two records have the same COL1 value, only one row should be in my result.

Let me give you an example:
COL1 COL2
RECORD1 1-A HHH
RECORD2 1-A GGG
RECORD3 1-B LLL
RECORD4 1-B MMM
RECORD4 1-B OOO
RECORD5 1-C NNN

Me result should be:


COL1 COL2
RECORD 1-A HHHGGG
RECORD 1-B LLLMMMOOO
RECORD 1-C NNN

It is clear what I need? I dont know if I can solve it through sql or any function inside SSIS.
Thanks for any help you can give me.

View 5 Replies View Related

SQL Server 2012 :: Query For Single Entry Record Only?

May 26, 2015

I have records like below, single query to get result below, basically records that has single entry only, which has type '0'

table : temp_test
idtype
c10
c25
c30
c40
c47
c59
c64
c60
c77
c80
c90

Result out of query

idtype
c10
c30
c80
c90

View 4 Replies View Related

Transact SQL :: Pull All Records From One Table And Just A Single Record From Another

Aug 7, 2015

I'm trying to pull all records from one table and just a single record from another.  I have this join, (see below).  It works ok, but the problem is if a blog record doesn't have a corresponding image record it doesn't return.  The end result should be the blog record and a single corresponding image record.  But always a blog record.

SELECT
[Blogs].[ID],
[Blogs].[BlogTitle],
[Blogs].[BlogType],
[Blogs].[BlogText],

[code]...

View 6 Replies View Related

Transact SQL :: How To Select A Single Record In A Left Join

Sep 16, 2015

My tables look like this:

 Users //
table
 UserID // pk
 UserName // varchar
UserFamilyName // varchar
User_Friends //
table
 FriendsID // pk
 UserID // fk
 FamilyName // varchar

MY query:

 SELECT
U.UserFamilyName, F.FamilyName
 FROM  
Users U LEFT
JOIN User_Friends
F ON U.UserID = 
F.UserID
 WHERE     
U.UserName = ‘JOHN’

How do I adjust my query to select just the very first record from Users_friends, I want only the top first one.And if there are no friends how can I return an empty string instead of Null.

View 10 Replies View Related

.NET Class To Hold Single Disconnected Record? Nothing Smaller Than DataSet?

Jul 9, 2007

What is the most efficient standalone .NET class that can hold a single disconnected record?  The class must also retain column names, but other schema is not relevant (.NET data type is sufficient).If I understand System.Data.Common.DbDataRecord, it provides an interface on a DbDataReader, and has no storage of its own.I'm familiar with DataSet, is that the only .NET-standard class to do this? Thank you,Shannon 

View 7 Replies View Related







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