Forum Replies Created

Viewing 15 posts - 1,036 through 1,050 (of 1,491 total)

  • RE: ORDER BY

    In the data you have provided the OrderId looks as though it may contain a 2 digit year.

    If this is the case then something like the following may work:

    ORDER BY

    &nbsp&nbsp&nbsp&nbspCASE

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN...

  • RE: Local Variable declaration in SQL 2000 and 2005

    Strange Syntax.

    SQL2000 seems to ignore the SET as does SQL2005 against a version 80 db.

  • RE: multiple joins necessary or redundant for distinct aggregates?

    Use CASE. MAX will ignore the NULLs. eg:

    SELECT YourId

    &nbsp&nbsp&nbsp&nbsp,MAX(CASE WHEN othertable.field > 4 THEN YourDate END)

    &nbsp&nbsp&nbsp&nbsp...

  • RE: Numbering groups of rows

    Try something like:

    SELECT T1.[Order], T1.OpNo, T1.Operation

    &nbsp&nbsp&nbsp&nbsp,DENSE_RANK() OVER (ORDER BY T1.[Order], MAX(T2.OpNo)) AS GroupID

    FROM YourTable T1

    &nbsp&nbsp&nbsp&nbspJOIN YourTable T2

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspON T2.Operation = 'SETG'

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND T1.[Order] = T2.[Order]

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND T1.OpNo >= T2.OpNo

    GROUP BY T1.[Order], T1.OpNo, T1.Operation

  • RE: Calculating man-hours per hour

    Or you could have the hour as a datetime to cope with multiple days. Something like:

    SELECT D.HourStart

    &nbsp&nbsp&nbsp&nbsp,SUM

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspCASE

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN D.HourStart >= S.StartTime AND D.HourEnd < S.EndTime

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspTHEN 60

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN D.HourStart &lt S.StartTime AND D.HourEnd...

  • RE: LOCK problem

    Try looking up 'Concurrency Control' in the SQL2000 Books Online.

  • RE: need a simple query

    It does not make a great deal of sense, but, for the given data, something like the following should work:

    SELECT D1.A, D1.B, D1.C, D2.D

    FROM

    (

    &nbsp&nbsp&nbsp&nbspSELECT ROW_NUMBER() OVER (PARTITION BY A ORDER...

  • RE: Cannot get value from SELECT statement

    The syntax is wrong. Try:

    SELECT @BuildID = BuildID ...

  • RE: Delete Statement: Why is this better?

    The second query may produce a lot of duplicate rows in tblFOO.

    Also, joins in subqueries always seem to be done with nested loops which is rarely efficient.

    (Derived tables are fine.)

    If...

  • RE: The flow of an UPDATE STATEMENT with a FROM CLAUSE

    Already answer - something wrong with my connection today.

  • RE: The flow of an UPDATE STATEMENT with a FROM CLAUSE

    Opps - already answered

  • RE: sp_executesql parametrized & output parameter

    The variable @VField_SP needs to be incorporated into the dynamic select.

    It will not work as a parameter. Something like:

    DECLARE @VField_SP nvarchar(300)

    &nbsp&nbsp&nbsp&nbsp,@VLKL_LSD_ID int

    &nbsp&nbsp&nbsp&nbsp,@PResult varchar(300)

    &nbsp&nbsp&nbsp&nbsp,@SQLString nvarchar(4000)

    SELECT @VField_SP = 'LKL_DOCUMENT_NR'

    &nbsp&nbsp&nbsp&nbsp,@VLKL_LSD_ID = 45464

    SET...

  • RE: SQL query to subtract two columns

    Maybe something like:

    SELECT A.AccountNumber

    &nbsp&nbsp&nbsp&nbsp,A.CustomerName

    &nbsp&nbsp&nbsp&nbsp,D.subtotal14 + D.vat14 - D.Payment14 AS [InvoiceBalance(0-14 Days)]

    &nbsp&nbsp&nbsp&nbsp,D.subtotal31 + D.vat31 - D.Payment31 AS [InvoiceBalance(15-31 Days)]

    FROM Accounts A

    &nbsp&nbsp&nbsp&nbspJOIN

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT S.AccountID

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp,ISNULL(SUM(CASE WHEN S.dateandtime >= DT.DT14 THEN S.subtotal END), 0) AS...

  • RE: Collation issue

    You could try checking your SP for #temp tables and table variables. If you are using these then adding COLLATE DATABASE_DEFAULT to the definitions of string columns may solved your...

  • RE: Complex Case Statement in an Update

    Maybe:

    DECLARE @TempTbl TABLE

    (

    &nbsp&nbsp&nbsp&nbspCol1 char(7)

    &nbsp&nbsp&nbsp&nbsp,Col2 char(7)

    &nbsp&nbsp&nbsp&nbsp,Col3 char(7)

    &nbsp&nbsp&nbsp&nbsp,Case_Col bigint

    )

    INSERT INTO @TempTbl

    SELECT Col1, Col2, Col3, MIN(Case_Col)

    FROM tbleActualDBTable

    WHERE Case_Col > 0

    GROUP BY Col1, Col2, Col3

    HAVING COUNT(Case_Col) > 1

    otherwise post some sample data with...

Viewing 15 posts - 1,036 through 1,050 (of 1,491 total)