all groups > sql server programming > february 2005 >
You're in the

sql server programming

group:

User defined data type UDF question.


User defined data type UDF question. Vern
2/7/2005 4:37:01 PM
sql server programming:
I'm using user defined data types in my stored procedures and they seem to
work fine. However, if I use the query analyzer to call the stored
procedure, and try to define the parameters using the user defined data type,
it says that data type doesn't exist. Is there something special to
specifying the UDF?

Here's the SQL in the query analyzer I'm trying to run.

CREATE TABLE #Address2 (AddressId int, Address1 char(50) )
INSERT #Address2 (AddressId, Address1 )
EXEC dbo.prWS_Address_Select 11, 0
SELECT * FROM #Address2
DROP TABLE #Address2

It works fine like that, but doesn't work if I change the first line to this:

CREATE TABLE #Address2 (AddressId AddressId, Address1 Address )

The stored procedure looks like this:

CREATE PROC [dbo].prWS_Address_Select
@AddressId int,
@err INT OUT
AS
SET NOCOUNT ON
SET @err = 0


SELECT AddressId,
Address1
FROM Address
WHERE AddressId = @AddressId
SELECT @err = @@error IF @err <> 0 RETURN -1
RETURN


RE: User defined data type UDF question. Ram Kumar Koditala
2/7/2005 4:51:05 PM
User defined data types are not allowed in temp tables
Hope this help you
thanks,
Ram Kumar

[quoted text, click to view]
RE: User defined data type UDF question. Vern
2/7/2005 5:23:02 PM
That was it, Thanks!

I can't believe they designed it to be different for temporary tables.
Figures that the first time I try to use it, I pick a temporary table for the
test:)

[quoted text, click to view]
Re: User defined data type UDF question. Vern
2/8/2005 8:53:04 AM
That makes sense. I forgot that temp files are actually created in tempdb.

Thanks.

[quoted text, click to view]
Re: User defined data type UDF question. Tibor Karaszi
2/8/2005 9:28:23 AM
You can use udf in temp table if the udf exists in tempdb:

USE pubs
EXEC sp_addtype 'myType', 'int'
GO
CREATE TABLE t(c1 myType)
GO
CREATE TABLE #t(c1 myType)
GO
USE tempdb
EXEC sp_addtype 'myType', 'int'
USE pubs
CREATE TABLE #t(c1 myType)

As tempdb is re-created on each start of SQL Server, you can add the udf to the model database.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/


[quoted text, click to view]

AddThis Social Bookmark Button