Results 1 to 5 of 5

Thread: Table Data Type and MS SQL 7.0

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Table Data Type and MS SQL 7.0

    Thanks to Szalmmany and Techgnome I was cruising along with SPROCS on my MS SQL2005 DB but when I went to work today tragedy struck. The SPROCS that I spend a weekend creating will no t run on our MS SQL 7.0 box specifically 7.0 doesn't like this line:

    VB Code:
    1. DECLARE @ListTbl TABLE(InvUnit varchar(100)

    I am getting the following error:

    Quote Originally Posted by Query Analyzer
    Incorrect syntax near the Keyword 'Table'
    Here is a copy of the SPROC:

    VB Code:
    1. USE IADATA
    2. IF EXISTS (select * from syscomments where id = object_id ('TestSP'))
    3.     DROP PROCEDURE TestSP
    4.  
    5. GO
    6. CREATE PROCEDURE TestSP
    7.     /*Declare Variables*/
    8.     @ListStr varchar(100) /*Hold Delimited String*/
    9. AS
    10.  
    11. DECLARE @ListTbl Table (InvUnit varchar(50)) /*Creates Temp Table*/
    12. DECLARE @CP int /*Len of String */
    13. DECLARE @SV varchar(50) /*Holds Result */
    14.  
    15. While @ListStr<>''
    16. Begin
    17.     Set @CP=CharIndex(',',@ListStr) /*Sets length of words - Instr */
    18.     If @CP<>0
    19.     Begin
    20.         Set @SV=Cast(Left(@ListStr,@CP-1) as varchar) /*Copies Portion of String*/
    21.         Set @ListStr=Right(@ListStr,Len(@ListStr)-@CP) /*Sets up next portion of string*/
    22.     End
    23.     Else
    24.     Begin
    25.         Set @SV=Cast(@ListStr as varchar)
    26.         Set @ListStr=''
    27.     End
    28.     Insert into @ListTbl Values (@SV) /*Inserts variable into Temp Table*/
    29. End
    30.  
    31. Select InvUnit From @ListTbl LT
    32. INNER Join dbo.Incidents ST on ST.Inv_Unit=LT.InvUnit

    Here is a link to the post

    BTW, this SP runs fne on a MS SQL2005 box. Any Ideas?
    Last edited by Mark Gambo; May 15th, 2006 at 06:05 AM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Table Data Type and MS SQL 7.0

    Table does not exist in SQL7, it was a new feature in SQL2K.

    Create Table #ListTbl (InvUnit varchar(50)) would be the equivalent.

    You should also include a Drop Table #ListTbl at the end of the sproc.

    Something as simple as this might work as well

    Select * From Incidents Where CharIndex(Inv_Unit,@ListStr) > 0
    Last edited by brucevde; May 15th, 2006 at 10:31 AM.

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Table Data Type and MS SQL 7.0

    Wow - supporting SQL 7.0 through SQL 2005 is quite a requirement...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Table Data Type and MS SQL 7.0

    Quote Originally Posted by szlamany
    Wow - supporting SQL 7.0 through SQL 2005 is quite a requirement...
    No not exactly, at work we have 7.0 but at home I have MSSQL 2000, MSSQL2K5 and MySQL 4.1. My job doesn't want to upgrade. Anyway I was aboiut to mark this tread Resolved anyway because I added another Variable and then masaged the input so that I got the desired results. Would it be better to do it the way you indicated or doing with variables?

    Thanks

    BTW when I get home I will post my solution.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Table Data Type and MS SQL 7.0

    Charindex will disallow index use in the QUERY - but will work efficiently for small recordsets.

    Building the table variable or temp table allows true "set-based" processing to handle the JOIN - so that indexes and proper query execution plans can be built.

    It's your call in the long run - I use both the CHARINDEX and the TABLE/INSERT/JOIN tricks myself.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width