Forum Replies Created

Viewing 15 posts - 736 through 750 (of 1,491 total)

  • RE: Union All - gets slow performance and timeout expired

    Looking at your views, I suspect blocking as well.

    (Bad stats may not help with this.)

    Try just using the tables and doing a FULL JOIN.

    Something like:

    SELECT

    CASE WHEN BIN.[Site] IS NULL THEN...

  • RE: Which one is better select * into # temp from tableA Vs create #temp table insert into...

    Another thing to consider is collation.

    SELECT INTO will always get the collation of character columns correct.

    If you do use the CREATE TABLE method then the collation should always be specified,...

  • RE: Working with UNION and NOT EXISTS

    Your code looks as though it will work although I would also be inclined to try an outer join to see if it is more efficient.

    Soemthing like:

    SELECT

    COALESCE(T1.Item, T2.Item) AS Item

    ,COALESCE(T1.Warehouse,...

  • RE: Update a record based on another record

    It depends on your data. Maybe:

    INSERT INTO TableA (Name, Location, Category, Code)

    SELECT 'Alex', Location, Category, Code

    FROM TableA

    WHERE Name = 'James'

    If this does not work, post some sample data, in consumable...

  • RE: join operator "=*"

    SELECT *

    FROM at_pdesc_off

    JOIN tb_Action

    ON at_pdesc_off.Action_id = tb_Action.Action_id

    AND tb_Action.delete_flg = 'N'

    -- * is against the table where all the rows should be kept.

    LEFT JOIN tb_code_value

    ON at_pdesc_off.pers_kind_cd = tb_code_value.code_value

    AND tb_code_value.code_subcat = 'PERS_KIND/PDOF'

    WHERE...

  • RE: Help needed on wrting SQL query

    1. In future, please provide data in a consumable format.

    eg

    CREATE TABLE #t

    (

    Col1 varchar(30) NOT NULL

    ,Col2 bit NOT NULL

    )

    INSERT INTO #t

    SELECT 'Ramu', 1

    UNION ALL SELECT 'Raju', 0

    UNION ALL SELECT 'Ravi', 1

    UNION...

  • RE: To select one month old record

    You will have to define what you want and fix it accordingly.

    eg. The following will produce 2011-01-28 to 2011-01-31 on 2011-02-28

    and 2011-02-28 on 2011-03-28, 2011-03-29, 2011-03-30 and 2011-03-31.

    ;WITH DateRange

    AS

    (

    SELECT

    DATEADD(day, DATEDIFF(day,...

  • RE: To select one month old record

    SELECT *

    FROM YourTable

    WHERE date1 >= DATEADD(day, DATEDIFF(day, 0, DATEADD(month, -1, CURRENT_TIMESTAMP)), 0)

    AND date1 < DATEADD(day, DATEDIFF(day, 0, DATEADD(month, -1, CURRENT_TIMESTAMP)), 1)

  • RE: Select Query

    Join to a numbers/tally table:

    http://www.sqlservercentral.com/articles/T-SQL/62867/

  • RE: Date as INT - having trouble with comparison :(

    To make the query SARGABLE you need to compare to an integer.

    Something like:

    WHERE table-name-removed >= YEAR(CURRENT_TIMESTAMP - 7) * 10000 + MONTH(CURRENT_TIMESTAMP - 7) * 100 + DAY(CURRENT_TIMESTAMP - 7)

  • RE: sp_getapplock issue

    1. sp_getapplock applies a user defined application lock. It saves an applicaiton having to cope with locking tables.

    2. As sp_getapplock is waiting indefinately, SET LOCK_TIMEOUT must be set to -1...

  • RE: Question on JOIN

    It is far from clear what you want.

    I suspect you may need to use UNION ALL instead of JOIN.

    Maybe something like:

    ;WITH Combined

    AS

    (

    SELECT nRunId, nTotal, nWaste, -1 AS nProductRunId

    FROM LiveRun

    UNION ALL

    SELECT...

  • RE: Deleting rows from multiple tables using join

    DELETE can only delete rows from one table so you will need to delete from each table in the correct order.

    Something like the following:

    DELETE docBodyVersion

    WHERE EXISTS

    (

    SELECT *

    FROM document D

    WHERE D.docID...

  • RE: ISDATE difference from client and server

    Stuart Davies (3/17/2011)


    On the face of it I would agree with you. However I have checked for differences in SQL and OS languages on any machines I have tried this...

  • RE: ISDATE difference from client and server

    It must be the date format. Is you server set to US English and your machine to British English?

    Try the following:

    SET DATEFORMAT dmy

    SELECT ISDATE('27/1/2011')

    SET DATEFORMAT mdy

    SELECT ISDATE('27/1/2011')

    SET DATEFORMAT ymd

    SELECT ISDATE('27/1/2011')

    Edit:...

Viewing 15 posts - 736 through 750 (of 1,491 total)