Forum Replies Created

Viewing 15 posts - 106 through 120 (of 128 total)

  • RE: Displaying query command with results in Query Analyzer

    Using Query Analyzer,

    Select Tools | Options | Results

    check the "Output Query" checkbox.

     

  • RE: Last Day of each month function?

    End of month logic for "YourDate":

    DATEADD(d, -1, DATEADD(m, 1 + DATEDIFF(m, 0, @YourDate), 0))

     

     

    Also, first of month logic:

    DATEADD(m, DATEDIFF(m, 0, @YourDate), 0)

     

     

     

  • RE: Returning IDENTITY from Linked Server

    Your statement

    select IDENT_CURRENT([linkedserver].database.table) 

    should be

    select IDENT_CURRENT([linkedserver].database.dbo.table) 

    The owner is a required piece of the four-part name.

     

  • RE: date comparison help

    select * from t

    where DATEDIFF(m, testdate,  GetDate()) > 0

     

  • RE: Need Guru: CONVERT vs homegrown function to clear time from datetime

    DATEADD(d, DATEDIFF(d, 0, @YourDate), 0)

    This works for smalldatetime and datetime, and does not involve conversions to other datatypes.

     

  • RE: How do I Sort by Name?

    What about this in the ORDER BY clause...

     

    ORDER BY CASE WHEN tbl_CompanyCategories.vcName = 'other' THEN 1 ELSE 0 END, tbl_CompanyCategories.vcName

     

     

  • RE: Question About Date Data

    There is no sense in updating a Field to its current value.

     

    Update MyTable set AlteredDate = case td

    when 'N' then dateadd(d, -2, ed)

    else dateadd(d, -1, ed) end

    where td IN ('I', 'N')

  • RE: GetDate ?

    In place of

    WHERE     (data.tblBooking.DateD >= GETDATE())

    use

    WHERE  (DATEDIFF(d, GETDATE(), data.tblBooking.DateD) > 0)

    No conversions, no substrings, works with or without non-midnight time portion.

     

  • RE: Divide by zero error.

    Or, simply replace the offending zero in the divisor with NULL:

     

    NULLIF((TOTAL_LOGIN_TIME - TOT_WAIT_TIME), 0)

     

    This will cause the entire calculation to return NULL.

    Then, if necessary, deal with the resulting NULL afterwards.

     

     

  • RE: Order by problem

    It appears Microsoft is doing something like "WITH TIES" behind the scenes for 100 PERCENT.  However, for values other than 100 PERCENT, the resultset CAN change, as your test data...

  • RE: Order by problem

    A correction to logic posted earlier...

    create view dbo.foobar

    as

    select top 100 percent WITH TIES * from authors order by au_lname

    go

    select * from dbo.foobar

    drop view dbo.foobar

     

    December 1, 2004 at 8:31 am

    #532060

  • RE: Last Date Of Month script

    Newbie,

    For '2004-01-30', your SQL returns 28.

    This is, obviously, not the last day of the month in question, January.

    Try this:

    Determine the first day of the specified month;

    Add 1 month;

    Subtract 1 day.

     

    DECLARE @Date datetime

    SET @Date...

  • RE: how write an Immediate If in SQL

    A NULL-safe variation of Antares' SQL changes the NULL to an empty string:

    ISNULL(CASE WHEN @EmployeePhone is NULL THEN NULL ELSE '<EmployeePhone>' + @EmployeePhone + '</EmployeePhone>, '')

  • RE: Generating Random Numbers?

    SELECT *

    FROM YourTable

    ORDER BY City, CASE YourBoolean WHEN 1 THEN NEWID() ELSE CustName END

  • RE: Redirect Message Output

    Look at isql for version 6.5.

Viewing 15 posts - 106 through 120 (of 128 total)