Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Conditional Logic to Create Function

Author  Topic 

mhg1063
Starting Member

27 Posts

Posted - 2004-05-03 : 13:17:21
Has anyone tried to create a function (UDF) based on conditional logic? I want to check for the existence of a column if the column exists in the table then create the function. I can do it with dynamic sql. Without the dynamic sql I get the create function has to be first in the batch. I was wondering if there is another way.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-05-03 : 13:22:53
Why don't you know if the column exists already?

Tara
Go to Top of Page

mhg1063
Starting Member

27 Posts

Posted - 2004-05-03 : 13:38:58
Because its for an application. The application uses sql server as the backend. The table is customizable. The table has ten standard columns but cutomers are allowed to add more depending on the data they want to audit. Most clients may have the column. But they will be some older clients that may not conform.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-05-03 : 22:16:21
If you are using customisable tables like this then it is probably better to hold the description in a table rather than alter the table definitions.

You can have in a table to define the customised columns

tablename
columnname
columntype
ID

then another table to hold the data
ID
BaseTablePK
Value

Then you can appear to the client that you are adding columns without changing the structure.

For your question - creates have to be the first statement in a batch hence must be preceeded by a go so can't be included in an SP but need to be executed as dynamic sql or osql or openquery or something similar which starts a new batch..

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -