Forum Replies Created

Viewing 15 posts - 361 through 375 (of 898 total)

  • RE: Getting minimum of top n rows without using subquery

    winmansoft (2/27/2013)


    You mean "select min([date]) from entries WHERE [date] BETWEEN '01-Jan-2012' and '20-Jan-2013'"? But we want to select minimum from top 100 rows

    Chris has compared all the methods for you...

  • RE: Data query

    One way to achieve this

    SELECT*

    FROMB AS B

    WHERE Status = 'Closed'

    ANDNOT EXISTS( SELECT * FROM B AS B1 WHERE B.IDA = B1.IDA AND B1.IDA <> 'Closed' )

  • RE: Getting minimum of top n rows without using subquery

    Gazareth (2/27/2013)


    Your ascending ordering in the subquery means they're logically the same. If you were ordering by date descending then that would be a different matter.

    Exactly.

    winmansoft (2/27/2013)


    I don't think that...

  • RE: Getting minimum of top n rows without using subquery

    Yes. It does and you can simplify it further as below

    select min([date]) from entries WHERE [date] BETWEEN '01-Jan-2012' and '20-Jan-2013'

  • RE: Execute Stored Procedure Multiple Times

    If there is a requirement where calling the stored procedure becomes unavoidable, a CURSOR or WHILE loop approach is fine and can't be avoided

    But, if the requirement can be satisfied...

  • RE: Getting minimum of top n rows without using subquery

    What is the need to use a sub-query?

    I don't see any difference between the below queries or am I missing something.

    SELECT min([date]) FROM table WHERE [date] IN (select top(100) [date]...

  • RE: Cannot create a row of size XXXX which is greater than the allowable maximum row size of 8060

    Warning: The table "Temp" has been created, but its maximum row size exceeds the allowed maximum of 8060 bytes. INSERT or UPDATE to this table will fail if the resulting...

  • RE: Compare the data in two tables, If Different, Update

    There are 3 rows which are different as per the sample data provided

    UPDATEOD

    SETOD.FirstName = UD.FirstName,

    OD.LastName = UD.LastName,

    OD.Birthdate = UD.Birthdate,

    OD.AreaCode = UD.AreaCode,

    OD.PhoneNumber = UD.PhoneNumber

    FROM#OriginalData AS OD

    INNER JOIN #UpdatedData AS UD

    ONOD.MemberID =...

  • RE: OUTPUT - 1

    handkot (2/26/2013)


    the answer is ambiguous and depends from collations

    I agree somewhat

    The answers will change if the database collation is case sensitive

    But, overall a very good question.

  • RE: Calculate an expression

    You can use Dynamic SQL to handle the scenario

    But, be really careful about SQL Injection and take necessary steps to avoid it

    CREATE PROCEDURE dbo.usp_ShowExpressionResults

    (

    @Expression NVARCHAR(MAX)

    )

    AS

    BEGIN

    SET @Expression = 'SELECT ' +...

  • RE: SQL server 2008 query help

    Not sure, but I feel this is what you are after

    SELECTL01, LO3, COUNT (*) Counts

    FROM(

    SELECTA.L01, A.L03, A.L39, B.A04, B.A10, B.A31

    FROM[LEARNER_SN05]AS A

    INNER JOIN(

    SELECTL01, L03, A04, A10, A31

    FROM[AIMS_SN05]

    WHEREA04 <> 35

    ANDA10 IN (10,...

  • RE: Interesting Question in SQL

    This should give the result you are looking for..

    DECLARE @t TABLE( ID INT, ColA CHAR(20), ColB CHAR(20), ColC CHAR(20) )

    INSERT INTO @t(ID, ColA, ColB, ColC )

    VALUES

    ( 1, 'India', 'VP', 'Mumbai'...

  • RE: Interesting Question in SQL

    You can make some changes to Mark's query as below

    DECLARE @t TABLE( ID INT, ColA CHAR(20), ColB CHAR(20), ColC CHAR(20) )

    INSERT INTO @t(ID, ColA, ColB, ColC )

    VALUES

    ( 1, 'India', 'VP',...

  • RE: Exclude duplicates, keep the value with the latest date

    You can also use ROW_NUMBER()

    SELECT*

    FROM(

    SELECTROW_NUMBER() OVER ( PARTITION BY CandidateID ORDER BY YourDateColumn DESC ) AS RN, *

    FROMYourTable

    ) AS YT

    WHEREYT.RN = 1

  • RE: Find first appointment after discharge from hospital

    Another way using CROSS-APPLY

    SELECTD.UnitNumber, D.IDXMRN, D.DischargeDate, App.ApptDt2, DATEDIFF( DAY, D.DischargeDate, App.ApptDt2 ) AS Days_Difference

    FROMDischarges AS D

    OUTER APPLY(

    SELECTTOP 1 *

    FROMAppointments AS A

    WHERED.UnitNumber = A.UnitNumber AND D.IDXMRN = A.IDXMRN

    ANDD.DischargeDate < A.ApptDt2

    ) AS...

Viewing 15 posts - 361 through 375 (of 898 total)