Forum Replies Created

Viewing 15 posts - 1,096 through 1,110 (of 1,497 total)

  • RE: Row level lock

    Try using a transaction and UPDLOCK.

    Here is an outline - you will need to add error handling etc.

    DECLARE @NextInvoiceNumber int

    BEGIN TRANSACTION

    SET @NextInvoiceNumber =

    (

    &nbsp&nbsp&nbsp&nbspSELECT NextInvoiceNumber

    &nbsp&nbsp&nbsp&nbspFROM InvoiceNumbers WITH (UPDLOCK)

    &nbsp&nbsp&nbsp&nbspWHERE Company =...

  • RE: Problem in Query

    Try something like:

    SELECT *

    FROM ord1 H

    WHERE EXISTS

    (

    &nbsp&nbsp&nbsp&nbspSELECT NULL

    &nbsp&nbsp&nbsp&nbspFROM PRCR C

    &nbsp&nbsp&nbsp&nbspWHERE C.customer = H.customer

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.division = H.division

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.ack_by = 'P'

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.sku_upc <> 'N'

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND C.ovnd_key IN (H.ovnd_key, '')

    )

  • RE: CTE Query

    Maybe you could try variations on:

    SELECT T3.IDK, T3.C4

    FROM T3

    WHERE EXISTS

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT *

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM T1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE T1.C1 = T3.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND EXISTS

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT *

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM SelField S

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE S.val = T1.C1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp)

    &nbsp&nbsp&nbsp&nbsp)

    &nbsp&nbsp&nbsp&nbspAND EXISTS

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT T2.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM T2

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHERE T2.IDK = T3.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspGROUP BY T2.IDK

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspHAVING...

  • RE: Unusual syntax

    I think these are the ODBC functions which TSQL seems to be able to process.

  • RE: CTE Query

    Get rid of the second WITH.

  • RE: Substring

    DECLARE @s varchar(255)

    SET @s = 'Mark_m_andrew_levey_caa12002'

    SELECT REVERSE(LEFT(REVERSE(@s), CHARINDEX('a', REVERSE(@s)) - 1))

  • RE: Data Orientation Problem

    SELECT TOP 30

    &nbsp&nbsp&nbsp&nbspS.Prod

    &nbsp&nbsp&nbsp&nbsp,S.Acct

    &nbsp&nbsp&nbsp&nbsp,S.TC

    &nbsp&nbsp&nbsp&nbsp,CASE N.N

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN 1 THEN S.SubmitRep1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN 2 THEN S.SubmitRep2

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspELSE S.SubmitRep3

    &nbsp&nbsp&nbsp&nbspEND AS Rep

    &nbsp&nbsp&nbsp&nbsp,CASE N.N

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN 1 THEN S.Percent1

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWHEN 2 THEN S.Percent2

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspELSE S.Percent3

    &nbsp&nbsp&nbsp&nbspEND AS Percentage

    FROM dbo.tbl_CYProcessedSales S

    &nbsp&nbsp&nbsp&nbspCROSS JOIN -- make 3...

  • RE: Distinct Latest Records

    SELECT U.*

    FROM Usr_AmtDetails U

    &nbsp&nbsp&nbsp&nbspJOIN

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT X.AcctID, MAX(X.RenewDate) AS RenewDate

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM Usr_AmtDetails X

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspGROUP BY X.AcctID

    &nbsp&nbsp&nbsp&nbsp) D

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspON U.AcctID = D.AcctID

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND U.RenewDate = D.RenewDate

  • RE: Simple LEFT JOIN gives surprising result - Why?

    I do not see any problem.

    What logically happens for a left join is:

    1. An inner join is done.

    2. Any rows in the left table not in the result are added.

    3....

  • RE: complex sql query

    If you check my Rolling Total query, you will see I am grouping by M2.userhistoryid

  • RE: complex sql query

    Umm.... You obviously did not try my original query as no rows would be returned.

    In future, please read the following when posting:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    As you seem to want a rolling total, try...

  • RE: complex sql query

    You need to get the required userid's and then use them with a derived table or a subquery.

    Here is an example of a derived table:

    SELECT M.*

    FROM moviesviewed M

    &nbsp&nbsp&nbsp&nbspJOIN

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT M1.userid

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM moviesviewed...

  • RE: multi-part identifier could not be bound

    Try getting rid of the brackets:

    SELECT P.user_permissions_id

    &nbsp&nbsp&nbsp&nbsp,U.[user_name] AS [User]

    &nbsp&nbsp&nbsp&nbsp,UA.[user_id]

    &nbsp&nbsp&nbsp&nbsp,A.abreviation AS Account

    &nbsp&nbsp&nbsp&nbsp,UA.account_id

    &nbsp&nbsp&nbsp&nbsp,P.[read] AS [Read]

    &nbsp&nbsp&nbsp&nbsp,P.write AS [Write]

    FROM q_user_account UA

    &nbsp&nbsp&nbsp&nbspJOIN t_users U

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspON UA.[user_id] = U.[user_id]

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspAND U.active = 1

    &nbsp&nbsp&nbsp&nbspJOIN t_account A

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspON UA.account_id = A.account_id

    &nbsp&nbsp&nbsp&nbspLEFT...

  • RE: Help with a troublesome query.

    Dale,

    My apologies – I did not visualize the joins correctly. (More coffee required!)

    I do not think HAVING can be used easily in this case.

    Ken

  • RE: Using 'OR' drastically increases execution time of query?

    BusinessObjectInstanceId = @BusinessObjectInstanceId

    OR

    @BusinessObjectInstanceId = ''

    Also, as BusinessObjectInstanceId is an integer, the implicit type casting will not help.

    Try OR @BusinessObjectInstanceId = 0

Viewing 15 posts - 1,096 through 1,110 (of 1,497 total)