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 June 10th, 2004, 10:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default table variables and udfs

I am trying to create a table variable for doing some record processing.

Code:
-- Create temporary table for  CityStateZIP
declare @tblcsz table
(
kCityStateZIP int
,sCSZ varchar(255) NULL
,kCountry varchar(10)
,kAddress int
,iFillLoc smallint
)
insert @tblcsz
select
    a.f1 as kCityStateZIP
    , a.f2 as sCSZ
    , a.f3 as kCountry
    , a.f4 as kAddress
    , a.f5 as iFillLoc
from
(
select 
    tcsz.PK_CityStateZIP as f1
    , NullIf(LTrim(RTrim(IsNull(NullIf(LTrim(RTrim(tcsz.CityName)) +
        ', ', ', '), '') + IsNull(NullIf(LTrim(RTrim(tcsz.StateAbbr)), ''), '') +
         ' ' + IsNull(NullIf(LTrim(RTrim(tcsz.FK_ZIP5)), ''), ''))), '')) as f2
    , tcsz.FK_Country as f3
    , ta.PK_Address as f4

-- The following line fails with error - Line 90: Incorrect syntax near '.'.
    , dbo.f_FindAllData(ta.AddrLine1, ta.AddrLine2, ta.AddrLine3, ta.AddrLine4) as f5
from dbo.t_CityStateZIP tcsz
left join t_Address ta on tcsz.PK_CityStateZIP = ta.FK_CityStateZIP
where tcsz.FK_Country NOT IN ('USA', 'ALASK', 'HAWAI')
  and tcsz.StateAbbr not in(select pk_state from t_state
) a
-- the following line fails with error - Line 95: Incorrect syntax near 'a'.
having sCSZ is not null

order by tcsz.PK_CityStateZIP
)
can anyone make any suggestions

Thank you in advance!



Rand
__________________
Rand
 
Old June 10th, 2004, 11:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Could that error be coming with your function?

Brian
 
Old June 10th, 2004, 11:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The function works fine independently or with a temporary table. It accepts four fields and returns an integer [0 - 15] indicating which fields (if any) have data.

If I replace the function with an integer (-1), I get the same error.

Rand





Rand
 
Old June 11th, 2004, 03:13 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I may be wrong, but I thing the HAVING clause needs to stay together with a GROUP BY clause.

Also, I would check the following code for possible parenthesis error, think there is one more ) than (

Code:
NullIf(LTrim(RTrim(IsNull(NullIf(LTrim(RTrim(tcsz.CityName)) +
        ', ', ', '), '') + IsNull(NullIf(LTrim(RTrim(tcsz.StateAbbr)), ''), '') +
         ' ' + IsNull(NullIf(LTrim(RTrim(tcsz.FK_ZIP5)), ''), ''))), '')) as f2







Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a List Box with Table Names & Table date hewstone999 Access VBA 1 February 27th, 2008 10:10 AM
Portability of User Defined Functions (UDFs) fredh Excel VBA 0 May 3rd, 2007 06:07 PM
Accessing UDFs in MS Access Module from VB6 tembe_c VB How-To 1 November 26th, 2005 08:31 AM
(oracle 8i)Alter Table <table> coalesce partition combo Oracle 3 October 13th, 2004 09:35 AM
size of table (type table is table of number) MikoMax Oracle 1 November 19th, 2003 03:11 AM





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