Forum Replies Created

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

  • 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

  • RE: DLINQ vs Stored Procedures

    To be fair, DLINQ, with it's dynamic SQL, is good for quickly creating prototypes. Also, if you decide to cache some data as XML, it saves having to know too...

  • RE: Help with a troublesome query.

    I started the query with the PO_MX table as you were looking for PONumbers - I find this easier but you can start with any table you like.

    You should also...

  • RE: Help with a troublesome query.

    In addition, derived tables, also known as inline views, could be used instead of HAVING:

    SELECT PO_MX.PONumber

    FROM PO_MX

    &nbsp&nbsp&nbsp&nbspJOIN

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT EJ.PONumber, SUM(EJ.Amount) AS Amount

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspFROM EJ

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspGROUP BY EJ.PONumber

    &nbsp&nbsp&nbsp&nbsp) D1

    &nbsp&nbsp&nbsp&nbspON PO_MX.PONumber = D1.PONumber

    &nbsp&nbsp&nbsp&nbspJOIN

    &nbsp&nbsp&nbsp&nbsp(

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspSELECT PO_DX.PONumber, SUM(PO_DX.QuantityOrdered...

  • RE: rownumber

    Without DDL and test data it is difficult to know what you want.

    Maybe you need to use the ROW_NUMBER() function like:

    SELECT *

    FROM

    (

    &nbsp&nbsp&nbsp&nbspSELECT ROW_NUMBER() OVER (PARTITION BY S.sessie_id ORDER BY S.created_date)...

  • RE: Add incremental count to group of rows

    1. Create a #temp table with an IDENTITY column

    2. Insert your data into the #temp table

    3. Join the #temp table to a derived table containing the MINIMUM(ID) for each tans_code...

  • RE: Add incremental count to group of rows

    In SQL2000 you will need to use a #temp table:

    http://www.sqlservercentral.com/Forums/Topic397675-8-1.aspx

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