Forum Replies Created

Viewing 15 posts - 1,336 through 1,350 (of 1,496 total)

  • RE: Ignoring CR LF when comparing columns

    Use the REPLACE function. Something like:

    SELECT *

    FROM TableA A

     JOIN TableB B ON A.PK = B.PK

    WHERE REPLACE(REPLACE(A.ColWithCRLF, CHAR(13), ''), CHAR(10), '') <> B.ColWithoutCRLF

     

  • RE: Converting date of birth to Age

    Floor nearly works but it produces a rounding error every 4 years as below:

    dob      Birthday FloorAge    CaseAge     RoundingError

    -------- -------- ----------- ----------- -------------

    19460624 19460624 0           0           N

    19460624 19470624 0           1          ...

  • RE: Converting date of birth to Age

    Kenneth,

    Nice use of modulus but your age calculation is wrong.

    eg. A child will come out as 1 year old when he/she is one day old.

    Looking back in this thread, my...

  • RE: sp_execute vs. sp_executesql

    sp_execute and sp_executesql are not the same thing.

    sp_execute is used with prepared statements by client APIs. (ODBC, ADO.NET etc)

    sp_executesql is used by tsql for dynamic queries.

     

  • RE: Lock and return row X from table

    You will need to use a transaction and have an UNIQUE CONSTRAINT/INDEX on Number. Something like:

    SET XACT_ABORT ON -- or add your own error handling

    DECLARE @NextNumber int

    BEGIN TRANSACTION

    -- This will...

  • RE: Are inner and outer joins commutative?

    As B, C and D are joining to A, you should get the same results from all three queries.

    The optimizer may behave differently with different join orders. You need to...

  • RE: COALESCE in the setting relationships

    Gabola71,

    Have you managed to get the execution plans for the query before and after COALESCE was applied?

    If you are short on time, it would be good just to compare the...

  • RE: Pulling my hair out! Multivalued column with key/value pairs to multiple rows.

    1. Yes:

    'X' + NULL = NULL

    while

    'X' + ISNULL(NULL, '') = 'X'

    or

    'X' + COALESCE(NULL, '') = 'X'

    etc

    2. OK

    3. Ouch. Bad design on top of bad design!

  • RE: Pulling my hair out! Multivalued column with key/value pairs to multiple rows.

    1. As you LEFT JOIN to t2, you need an ISNULL around any mention of t2.criteriadata.

    2. Can linenum ever exceed 1?

    3. Can key/value pairs ever cross a linenum boundary?

     

  • RE: Pulling my hair out! Multivalued column with key/value pairs to multiple rows.

    I would be inclined to:

    1. add OPTION (MAXDOP 1) to Farrell's query, as it may be safer.

    2. create the temp table/variable first, to reduce schema locking.

    Also, why not use the...

  • RE: Suppressing output from a stored procedure.

    You could try re-directing the output to the nul console by adding > nul:

    select @cmd ='C:\"Program Files (x86)"\"Microsoft SQL Server"\90\DTS\Binn\DTExec.exe /DTS "'

  • RE: Insert Value into table

    This seems like a pointless exam question. DEFAULT VALUES may be what you want:

    DECLARE @t TABLE

    (

     TID int IDENTITY NOT NULL

    )

    INSERT INTO @t DEFAULT VALUES

    INSERT INTO @t DEFAULT VALUES

    INSERT INTO @t...

  • RE: COALESCE in the setting relationships

    Sergiy,

    While appreciating your comments about the join expression and the need for correct indexes, I think the COALESCE functions here may be tricking the optimizer. (Gabola did say that the...

  • RE: NOT EXISTS vs. NOT IN (subquery)

    If tblLinks also has an ID column, then the optimizer may be getting confused about which ID column to use.

    With more than one table, it is good practise to use...

  • RE: Converting my SELECT into a DELETE

    or

    DELETE FROM titleauthor

    WHERE EXISTS (

     SELECT *

     FROM titles T

     WHERE T.title LIKE '%Straight%'

      AND T.title_id = titleauthor.title_id )

Viewing 15 posts - 1,336 through 1,350 (of 1,496 total)