Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2004, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default Function in query

I am trying to convert an Access query that uses a custom function into an MS SQL2000 stored procedure (or in-line function) but not sure how to deal with the custom function.

Here is the SQL from Access:

Code:
SELECT T_SSKC.KitID,
      T_SSKC.KitQuoteID,
      T_SSKC.KitItemPartNum,
      T_SSKC.CompQuoteID,
      T_SSKC.CompItemPartNum,
      T_SSKC_1.KitID AS CompKitID,
      T_SSKC.CompQty,
      BaseKit(T_SSKC.[KitID],
     T_SSKC.[KitItemPartNum],
     T_SSKC.[CompItemPartNum],
     T_SSKC.[CompQty]) AS BaseKit,
      DivideBy(T_SSKC.[KitID],
     T_SSKC.[KitItemPartNum],
     T_SSKC.[CompItemPartNum],
     T_SSKC.[CompQty]) AS DivideBy
FROM T_SSKC 
INNER JOIN T_SSKC AS T_SSKC_1 
     ON T_SSKC.CompItemPartNum = T_SSKC_1.KitItemPartNum
GROUP BY T_SSKC.KitID,
      T_SSKC.KitQuoteID,
      T_SSKC.KitItemPartNum,
      T_SSKC.CompQuoteID,
      T_SSKC.CompItemPartNum,
      T_SSKC_1.KitID,
      T_SSKC.CompQty
And here is the Access custom function:

Code:
Public Function BaseKit(KitID, KitItemPartNum, CompItemPartNum, CompQty) As Variant
'This drills down until it finds the actual items needed to produce a kit

Dim rstKits As Recordset, intBaseId As Integer, strFloatingCompItem As String

If IsNull(CompItemPartNum) = False Then
    intBaseId = KitID
    strFloatingCompItem = CompItemPartNum

    Set rstKits = CurrentDb.OpenRecordset("T-SetupSheetKitComponents")
    rstKits.MoveFirst
    Do Until rstKits.NoMatch = True
        rstKits.FindFirst "[KitItemPartNum]=""" & strFloatingCompItem & """"
        If rstKits.NoMatch = False Then intBaseId = rstKits.Fields("[KitID]")
        strFloatingCompItem = rstKits.Fields("[CompItemPartNum]")
    Loop

    BaseKit = intBaseId
Else
    BaseKit = Null
End If

End Function
Do I turn the custom Access function into a MS SQL function or do I somehow do everything in one single, but long, stored procedure.

Either way, I probably also need some assistance in re-writing the Access custom function since I am not sure how to address converting it to anything.
__________________
Mitch





Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Function Query rsm42 ASP.NET 1.0 and 1.1 Basics 4 August 4th, 2007 05:29 AM
sql query VAL function itHighway Classic ASP Basics 1 February 23rd, 2005 11:55 AM
query related to function nimeshkumargupta SQL Server 2000 0 January 18th, 2005 04:05 AM
using format function in a query the_digs Access VBA 3 June 26th, 2004 01:22 AM
Date () function in MySQL query dcsteve72 Classic ASP Components 1 March 30th, 2004 07:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.