Forum Replies Created

Viewing 15 posts - 2,416 through 2,430 (of 4,085 total)

  • RE: Converting Getdate to smalldate

    There are several ways that you can accomplish this. Probably the most straightforward is the following.

    SELECT CAST(CAST(GETDATE() AS DATE) AS SMALLDATETIME)

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Export data from SQL server to multiple tabs

    It's possible to do this with SSIS, but SSIS is complicated enough that I would not recommend trying this as your first SSIS project.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Conversion failed when converting date and/or time from character string.

    All results of a CASE expression must be of compatible data types and the data type with the highest precedence determines the final data type. You return a mix...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: WeekNumners to be renamed

    John Mitchell-245523 (8/26/2016)


    There are pros and cons. Your query will return (possibly) unexpected results if there are gaps in the data or two dates in the same week. ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: WeekNumners to be renamed

    John Mitchell-245523 (8/26/2016)


    SELECT

    Time_Started

    ,ROW_NUMBER() OVER (ORDER BY DATEPART(wk,Time_Started)) AS Week_No

    FROM #tbl_data

    John

    Now try it with this data

    INSERT INTO #tbl_data (

    Time_Started

    )

    VALUES('2017-01-06 09:08:47.763'),

    ('2016-12-30 09:08:47.763'),

    ('2016-12-23 09:08:47.763'),

    ('2016-12-16 09:08:47.763');

    This is why I asked about wrapping and...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Running Total with different categories

    If by "slice", you mean filter, windowed functions are calculated after the WHERE clause, so the running total reflects any filters applied in the WHERE clause.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: WeekNumners to be renamed

    sharonsql2013 (8/25/2016)


    I am getting last 4 week numbers in a query - say 31 thru 33.

    How can I rename 31 as week 1 , 32 as week2 , 33 as...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Are the posted questions getting worse?

    Lynn Pettis (8/25/2016)


    Got to the following from a LinkedIn email. Not sure about a few of the answers.

    https://intellipaat.com/interview-question/sql-interview-questions/

    I had to stop after number 12. There is no way...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: query that returns seconds

    JALLYKAMOZE (8/25/2016)


    CREATE TABLE DELAYSECONDS(

    ProgramID INT, ID INT, ContractHeaderID INT, ContractStartTime TIME, ProgramStartTime TIME ,ContractDetailFirstDay INT ,ProgramFirstDay INT, DelaySeconds INT)

    INSERT INTO DELAYSECONDS

    VALUES (625, 625, 115278, '18:00:00', '18:00:00', 2, 2, 0),

    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Insert Into multiple values from Select plus adding incremental non-Identity

    Luv SQL (8/25/2016)


    I need to grab the sequence number from TableA not Table B.

    The sequence number IS coming from TableA.

    Part of the problem, is that you haven't been able to...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Insert Into multiple values from Select plus adding incremental non-Identity

    I think what you are looking for is ROW_NUMBER(). Something like the following:

    SELECT *, ROW_NUMBER() OVER(ORDER BY <pick some order here>) + ( SELECT MAX(sequence) FROM TableA)

    FROM TableB

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: query that returns seconds

    I haven't looked at the calculations, but replace your nested cursors with this. And why go to the trouble of specifying a name for the day of the week...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: get the price of last buy of each sell

    The Dixie Flatline (8/23/2016)


    Drew, the pattern of this data is what I think of as header/detail data. One very significant "S" row followed by a bunch of "B"...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: get the price of last buy of each sell

    There are obvious problems with the "expected results" -- such as all of the times being the same and dates in the results that don't exist in the sample data...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Converting a XML datatype to varchar(max).

    Yes, use a different approach. Either shred the XML and make your adjustments on the shredded data or use .modify() to modify your XML.

    Since you haven't provided sample data...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 2,416 through 2,430 (of 4,085 total)