Forum Replies Created

Viewing 15 posts - 49,456 through 49,470 (of 49,552 total)

  • RE: dynamic sql problem

    Why do you need a dynamic statement? I assume you're doing this in a stored proc, if not, adjust or whatever...

    I'm also assuming that you know the structure of 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: dynamic sql problem

    Don't think that's going to work, since @vtbl is a table type variable. If it was a string would be fine.

    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: dynamic sql problem

    It's a scope issue. The variable only exists at the outer level (where it was declared) so when the dynamic SQL executes, the table variable is not visible.

    See BoL under...

    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: Simple UPDATE Question

    Almost right

    UPDATE BalanceTable

    Set Vendor = VendorCodeTable.Vendor

    FROM VendorCodeTable

    You can optionally add a where clause after to do joins e.g.

    UPDATE BalanceTable

    Set Vendor = VendorCodeTable.Vendor

    FROM VendorCodeTable

    WHERE BalanceTable.Region=VenderCodeTable.Region

    HTH

    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: Second Largest Element

    Actually, come to think of it, it can.

    SELECT MAX(Element) FROM Table WHERE Element NOT IN (SELECT TOP 1 Element FROM table ORDER BY Element DESC)

    Replace TOP 1 with whatever you...

    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: Second Largest Element

    Select max(element) AS SecondLargest FROM

    Table WHERE Element!=(SELECT max(element) FROM Table)

    Unfortunatly not adaptable to give the third largest, etc. I'm sure someone around here has a more adaptable solution.

    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: max date

    Eeep, sorry.

    Remove all references to id and remove the group by in the inner query. I was thinking of somethng else.

    SELECT actionstatus, actiondatetime FROM tbl INNER JOIN

    (SELECT MAX(actiondatetime) AS...

    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: max date

    I assume you have some column that is unique. For the purposes of the eg, I will call that column ID. Also calling the table tbl

    SELECT actionstatus, actiondatetime FROM...

    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: multiple instance of SQL Server

    SET ANSI_NULLS ON

    GO

    SET ANSI_WARNINGS ON

    GO

    CREATE PROCEDURE [procTest]

    AS

    SELECT Shift_num

    FROM [bell-sql].CabTS.dbo.Shift

    GO

    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: How to write a MS-SQL function that makes nvl() look like isnull()

    Ownership confusion, most likely

    First it should be

    CREATE FUNCTION dbo.nvl(....

    then call it

    select dbo.nvl('123', '321') from my_table

    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: How to write a MS-SQL function that makes nvl() look like isnull()

    You could try and make the input and output datatypes sql_variant. It's not overly efficient, and may cause problems with implicit conversion, but should work.

    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: Scalar function help

    What you've created there is a computed column in the table, not a column with a default. The function is recursive as written, and will call itself without end, which...

    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: Cross tab or CASE ?

    Not sure how you want this displayed

    This is the easiest:

    Column 1Column 2
    Total TradesTotal Value
    Trades for Symbol1Value

    That can be achieved by unioning the selects together

    select '-Total-' AS Title, count(*) AS...

    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: problem calling a remote sp from a trigger

    Are either of the boxes Server 2003? If so, you might want to check this out.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;329332

    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: bit vs. tiny integer - Performance issue

    One thing to note is that bit fields are only really useful if there are multiple of them in a row.

    From BoL

    "If there are 8 or fewer bit columns...

    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,456 through 49,470 (of 49,552 total)