Forum Replies Created

Viewing 15 posts - 796 through 810 (of 1,491 total)

  • RE: Passing variables to SQL server Agent job OR asynchronous call of Stored Proc

    There is a large section on Service Broker in BOL (Books Online).

  • RE: Passing variables to SQL server Agent job OR asynchronous call of Stored Proc

    You can get the same effect by creating a QUEUE and using Service Broker.

  • RE: Case in where clause not working

    Maybe you want something like:

    WHERE [state] =

    CASE

    WHEN @statefilter = 2

    THEN 'CA'

    WHEN @statefilter = 3 AND [state] = 'CA'

    THEN 'ZZ' -- junk value

    ELSE [state]

    END

  • RE: Log shipping to UNC path issues?

    Could be network problems.

    I would be inclined to to the backups onto a local share and then have them copied to the other server.

  • RE: sp_executesql output parameter as table variable

    To pass a table variable you have to create a type and define the table as the type.

    What you are trying to do will not work as table variables can...

  • RE: Merge statement question

    You appear to selecting not merging.

    Try something like:

    SET ANSI_NULLS, QUOTED_IDENTIFIER ON

    GO

    CREATE PROCEDURE dbo.GetTblGUID

    @Address nvarchar(255)

    ,@GUID uniqueidentifier OUTPUT

    AS

    DECLARE @GUIDs TABLE

    (

    [GUID] uniqueidentifier NOT NULL

    );

    INSERT INTO Tbl

    OUTPUT inserted.[GUID] INTO @GUIDs

    SELECT NEWID(), @Address

    WHERE NOT EXISTS

    (

    SELECT...

  • RE: VARCHAR Sort Issue using MAX Function

    You may be best to do it all in one statement to avoid potential concurrency problems.

    Something like:

    ;WITH DivRows

    AS

    (

    SELECT RowNo, Division, UserName

    ...

  • RE: VARCHAR Sort Issue using MAX Function

    Add computed columns:

    ALTER TABLE dbo.PCList

    ADD PCNamePreFix

    AS

    (

    CAST

    (

    CASE PATINDEX('%[0-9]%', PCName)

    WHEN 1 THEN ''

    WHEN 2 THEN LEFT(PCName, 1)

    WHEN 3 THEN LEFT(PCName, 2)

    ELSE LEFT(PCName, 3)

    END

    AS varchar(3)

    )

    ) --PERSISTED

    , PCNameNumber

    AS

    (

    CAST

    (

    CASE PATINDEX('%[0-9]%', PCName)

    WHEN 0 THEN...

  • RE: Locking of Tables

    harinerella (1/4/2011)


    Simple solution could be applying UPDLOCK at the time of selection, which will not allow other sessions to lock the same row.

    You also have to apply a key range...

  • RE: Who is in the building? Query

    Try:

    SELECT usernumber

    FROM tblaccess

    WHERE readernumber IN (1,2,3,4,5,6)

    GROUP BY A.usernumber

    HAVING

    -- Max entry accessid (assuming accessid is an IDENTITY. If not use accessdatetime.

    MAX(CASE WHEN readernumber IN (1,2,3) THEN A.accessid ELSE 0 END)

    ...

  • RE: Who is in the building? Query

    Assuming your DDL is something like:

    CREATE TABLE tblaccess

    (

    accessid int IDENTITY NOT NULL

    PRIMARY KEY

    ,accessdatetime datetime

    ,usernumber int NOT NULL

    ,readernumber int NOT NULL

    )

    CREATE TABLE readernumbers

    (

    readernumber int NOT NULL

    PRIMARY KEY

    ,readerSet varchar(5)

    CHECK (readerSet IN ('entry',...

  • RE: Delete table with locks

    If the table is heavily used, you might have problems in obtaining a schema lock to do the sp_rename.

    You may have to look at doing an upsert and changing the...

  • RE: Try to build a SQL error string, but

    You can often get away with one generic exception handler.

    SET ANSI_NULLS, QUOTED_IDENTIFIER ON

    GO

    CREATE PROCEDURE dbo.ExceptionHandler

    AS

    SET NOCOUNT ON

    DECLARE @ErrorNumber int = ERROR_NUMBER()

    ,@ErrorSeverity int = ERROR_SEVERITY()

    ,@ErrorState int = ERROR_STATE()

    ,@ErrorProcedure nvarchar(126) = ERROR_PROCEDURE()

    ,@ErrorLine...

  • RE: Slow query when using specific date range = very frustrated

    Something like the following may be worth a try:

    SELECT o_num

    INTO #orders

    FROM orders

    WHERE o_type IN (9, 30)

    AND trn_id IN (24, 45, 25, 0)

    ALTER TABLE #orders

    ADD PRIMARY KEY (o_num)

    -- This assumes that...

  • RE: sp_executesql dynamic columns in select statement

    The sp_executesql procedure works like a dynamic SP so you can only pass values, and not object names, as parameters.

    To guard against SQL injection you can validate column names against...

Viewing 15 posts - 796 through 810 (of 1,491 total)