Forum Replies Created

Viewing 15 posts - 49,336 through 49,350 (of 49,552 total)

  • RE: stored procedure question

    The way I wrote that query it should only return one reply per post, unless you have replies with identical dates.

    Can you please post some example data and your...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: stored procedure question

    Specify the table for all the columns. I didn't know what your tables looked like, so I too a guess. My bad.

    SELECT TOP 20

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Trigger question

    What's with all the declared but unused variables?

    You've got an error handling block, but no error checking anywhere.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Finding Sum of different column...

    Doesn't matter how you capture the data. You've got 15 fields all storing the same thing in one table. That's bad db design. It may make the capturing easier, but...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: stored procedure question

    A subselect in the SELECt clause can only return 1 field. Join it is as a subquery.

    Do you want the latest reply for a post? (assuming so for the below...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Finding Sum of different column...

    Can you fix the database design? At the moment it's violating first normal form (table contains repeating groups). What happens if it's decided that a month of data needs to...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Time out error

    I just glanced over it quickly, but I've got a feeling that it can be optimised a bit.

    Can you please post table definitions, sample data and expected output. Also the...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: 7 Business Days after a specified Date

    No problem. What part don't you understand?

    The case statement takes the day of the week (Sunday=1, Monday=2,....) and based on that decides how many days to add to get 7...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: 7 Business Days after a specified Date

    Not particuarly elegent, but it works.

    set datefirst 7

    DECLARE @DayOfWeek TINYINT

    SET @DayOfWeek=datepart(dw,getdate())

    select DATEADD(dd,CASE WHEN @DayOfWeek<5 THEN 9 WHEN @DayOfWeek=7 THEN 10 ELSE 11 END, GETDATE())

    For today (Thurs 20th Oct) this returns...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: UDFs and ByRef parameters - help

    No. Stored procedures may have output parameters but functions may not. See the following from BoL.

    A user-defined function takes zero or more input parameters and returns either a scalar value...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Advise needed

    A job that runs once a day would work.

    Job checks for all records where datediff(dd,TraceDate,GETDATE())=7 AND TRStatus='Closed' The =7 ensures that the same record won't get flagged two days...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Help with prepared statement

    No problem.

    I can't see anything wrong either. If you replace the sp_executeSQL with Print, what's the resulting statement? (checking to see that nothing strange has snuck into the variables)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: top 1 and union

    That would be true, if there wasn't a TOP 1 in each of the subqueries.

    The final order of the union is undefined, but it consists of the first records in...

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: top 1 and union

    This however does work

    select Col1, Col2 FROM

     (select top 1 Col1, Col2 from TableA order by Col2) a

    UNION

    select Col3, Col4 FROM

     (select top 1 Col3, Col4 from TableB order by Col4) b

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • RE: Database becoming virtual single user system!

    How many processors does your server have?

    What connection settings/SET options is the app using?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 15 posts - 49,336 through 49,350 (of 49,552 total)