Forum Replies Created

Viewing 15 posts - 2,296 through 2,310 (of 3,543 total)

  • RE: Pivot Rows into Columns

    Bit long winded but might work

    CREATE TABLE #temp (rowid int IDENTITY(1,1), colid int,

    CustomerCode, AddressId, CustomerCode, a.AddressType, a.DateReceived, Line1, Line2, Line3, Line4, ZipCode)

    INSERT INTO #temp

    (colid, CustomerCode, AddressId, CustomerCode, a.AddressType, a.DateReceived,...

  • RE: Importing Excel into SQL - some columns import as NULL

    This because the engine used to read the spreadsheet tries to decide whether each column is char or numeric based on it's data (IIRC the first 7 rows). If any...

  • RE: Passing variable parameter in SP

    Maybe something like this

    DROP PROCEDURE usp_test

    GO

    CREATE PROCEDURE usp_test

     @a int = NULL,

     @b int = NULL,

     @c char(5) = NULL

    AS

    SELECT a,b,c

    FROM tbl1

    WHERE a = ISNULL(@a,a)

    AND...

  • RE: Creating report from one table

    My query will return two rows per customer!!

    We need more info if the query does not produce what you want

  • RE: Finding no of weekend days between two dates

    quoteAs I've said, use a calendar table.

    Maybe, maybe not, a lot of trouble for small return

  • RE: Creating report from one table

    or like this (will only work for one year!)

    SELECT Customer, [Type],

      SUM(CASE WHEN [Month] = 1  THEN [Value] ELSE 0 END) as [Jan],

      SUM(CASE WHEN [Month] = 2 ...

  • RE: Finding no of weekend days between two dates

    SET DATEFIRST 7

    SELECT ((DATEDIFF(week,[startdate],[enddate]) -

      (CASE WHEN DATEPART(weekday,[startdate]) IN (1,7)

            OR DATEPART(weekday,[enddate]) IN (1,7) THEN 1 ELSE 0 END)) * 2) +

      (CASE WHEN DATEPART(weekday,[startdate]) =...

  • RE: Nested Loops on cursors

    quoteThe problem is I cannot use @@Fetch_Status...

    You can but as stated in BOL you have to be...

  • RE: ABOUT TRIGGERS!!!

    Is this what you are trying to do?

    CREATE TRIGGER TRG_STOCKS ON [dbo].[T_STOCKS]

    FOR INSERT, UPDATE

    AS

    BEGIN

    UPDATE t

    SET [DESCRIPTION] = (CASE WHEN d.ITEM_NO IS NULL THEN 'NEW RECORD...

  • RE: delete rows less than 30 days

    or this might even work

    DECLARE @AUDITTIMESTAMP bigint

    SET @AUDITTIMESTAMP = SELECT CAST(DATEDIFF(day,'01/01/1970',DATEADD(day,-30,GETDATE())) as numeric) * 24 * 60 * 60 * 1000

    SELECT *

    FROM [Table]

    WHERE AUDITTIMESTAMP < @AUDITTIMESTAMP...

  • RE: delete rows less than 30 days

    If DATEADD(hh, - 05, DATEADD(ss, AUDITTIMESTAMP / 1000, '01/01/1970')

    returns the correct date (seems like this data is from a legacy system!)

    then you could do the following

    WHERE DATEDIFF(day,DATEADD(hh, - 05, DATEADD(ss,...

  • RE: DTS error handling when server down

    I have lots of dts packages like this, I use an 'Execute SQL Task' to do a select on the source table (using a single key) and only execute the...

  • RE: Need a RELIABLE table-exist test

    quoteI guess what I'm really asking is when should I check for object_id() is null

    object_id will return...

  • RE: Counting a consecutive condition

    nice

    slight change to reduce data for aggregates

    select distinct e1.emp_id

    from #emp e1

    INNER JOIN #emp e2

    on e1.emp_id = e2.emp_id

    and e2.met = 1...

  • RE: Sub Query Syntax

    or

    delete ol

    from tblorderline ol

    inner join tblOrders o

    on o.OrderID = ol.OrderID

    and o.Offercode = 'NWZ'

Viewing 15 posts - 2,296 through 2,310 (of 3,543 total)