473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get text of User Defined Functions?

I use the code below to generate a text file containing every stored
procedure and view in my SQL Server backend database, but I can't
figure out how to generate text of the User Defined Functions.

I see I can reference: SQLDMO.UserDefinedFunction
But can't find any way to reference dbs.<user defined functions>

Any help is greatly appreciated.
lq
Sub OutputDBQueries(myPath as String)

' In VB 6. Set a reference to Microsoft SQLDMO Object Library

Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim sptext As String

objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)

Open myPath For Output As #1

'>go through all stored procedures:
For Each sp In dbs.StoredProcedures

sptext = sp.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _

"************************************************* *****************************"
& _
vbCrLf & vbCrLf & vbCrLf
Next

'>go through all views:
For Each v In dbs.Views

sptext = v.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _

"************************************************* *****************************"
& _
vbCrLf & vbCrLf & vbCrLf
Next

MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"

End Sub

Jul 21 '06 #1
3 2306
Lyle,
Excellent. Thanks.
lq

Lyle Fairfield wrote:
Lauren Quantrell wrote:
I use the code below to generate a text file containing every stored
procedure and view in my SQL Server backend database, but I can't
figure out how to generate text of the User Defined Functions.

I see I can reference: SQLDMO.UserDefinedFunction
But can't find any way to reference dbs.<user defined functions>

Any help is greatly appreciated.
lq
Sub OutputDBQueries(myPath as String)

' In VB 6. Set a reference to Microsoft SQLDMO Object Library

Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim sptext As String

objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)

Open myPath For Output As #1

'>go through all stored procedures:
For Each sp In dbs.StoredProcedures

sptext = sp.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _

"************************************************* *****************************"
& _
vbCrLf & vbCrLf & vbCrLf
Next

'>go through all views:
For Each v In dbs.Views

sptext = v.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _

"************************************************* *****************************"
& _
vbCrLf & vbCrLf & vbCrLf
Next

MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"

End Sub

Air Code:

Dim c As ADODB.Connection
Dim s As String
Set c = New ADODB.Connection
c.Open "PROVIDER=SQLOLEDB.1;" _
& "INITIAL CATALOG=DB_51315;" _
& "DATA SOURCE=mssql04.discountasp.net;" _
& "USER ID=Whatever;" _
& "PASSWORD=YYSW"
s = "SELECT so.name, sc.text"
s = s & vbNewLine & "FROM SysComments sc"
s = s & vbNewLine & "JOIN SysObjects so"
s = s & vbNewLine & "ON sc.ID = so.ID"
s = s & vbNewLine & "WHERE so.xtype='FN'"
s = s & vbNewLine & "ORDER BY so.Name"
Debug.Print c.Execute(s).GetString(adClipString, , , vbNewLine)
Jul 21 '06 #2
Because you are using a SQLDMO.Database object when you should be using a
SQLDMO.Database2 object.

So your procedure should be somthing like

Sub OutputDBQueries(myPath As String)
Dim strSep As String
Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database2
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim f As SQLDMO.UserDefinedFunction

Dim sptext As String

strSep = vbCrLf & vbCrLf & vbCrLf _
& String(78, "*") _
& vbCrLf & vbCrLf & vbCrLf

objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)

Open myPath For Output As #1

'>go through all stored procedures:
For Each sp In dbs.StoredProcedures
sptext = sp.Text
Print #1, sptext & strSep
Next

'>go through all views:
For Each v In dbs.Views
sptext = v.Text
Print #1, sptext; strSep
Next

For Each f In dbs.UserDefinedFunctions
sptext = f.Text
Print #1, sptext; strSep
Next

MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"

End Sub

--

Terry Kreft
"Lauren Quantrell" <la*************@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
I use the code below to generate a text file containing every stored
procedure and view in my SQL Server backend database, but I can't
figure out how to generate text of the User Defined Functions.

I see I can reference: SQLDMO.UserDefinedFunction
But can't find any way to reference dbs.<user defined functions>

Any help is greatly appreciated.
lq
Sub OutputDBQueries(myPath as String)

' In VB 6. Set a reference to Microsoft SQLDMO Object Library

Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim sptext As String

objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)

Open myPath For Output As #1

'>go through all stored procedures:
For Each sp In dbs.StoredProcedures

sptext = sp.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _

"************************************************* **************************
***"
& _
vbCrLf & vbCrLf & vbCrLf
Next

'>go through all views:
For Each v In dbs.Views

sptext = v.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _

"************************************************* **************************
***"
& _
vbCrLf & vbCrLf & vbCrLf
Next

MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"

End Sub

Jul 22 '06 #3
Thanks Terry,
This is very nice and neat now.
lq

Terry Kreft wrote:
Because you are using a SQLDMO.Database object when you should be using a
SQLDMO.Database2 object.

So your procedure should be somthing like

Sub OutputDBQueries(myPath As String)
Dim strSep As String
Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database2
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim f As SQLDMO.UserDefinedFunction

Dim sptext As String

strSep = vbCrLf & vbCrLf & vbCrLf _
& String(78, "*") _
& vbCrLf & vbCrLf & vbCrLf

objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)

Open myPath For Output As #1

'>go through all stored procedures:
For Each sp In dbs.StoredProcedures
sptext = sp.Text
Print #1, sptext & strSep
Next

'>go through all views:
For Each v In dbs.Views
sptext = v.Text
Print #1, sptext; strSep
Next

For Each f In dbs.UserDefinedFunctions
sptext = f.Text
Print #1, sptext; strSep
Next

MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"

End Sub

--

Terry Kreft
"Lauren Quantrell" <la*************@hotmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
I use the code below to generate a text file containing every stored
procedure and view in my SQL Server backend database, but I can't
figure out how to generate text of the User Defined Functions.

I see I can reference: SQLDMO.UserDefinedFunction
But can't find any way to reference dbs.<user defined functions>

Any help is greatly appreciated.
lq
Sub OutputDBQueries(myPath as String)

' In VB 6. Set a reference to Microsoft SQLDMO Object Library

Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim sptext As String

objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)

Open myPath For Output As #1

'>go through all stored procedures:
For Each sp In dbs.StoredProcedures

sptext = sp.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _
"************************************************* **************************
***"
& _
vbCrLf & vbCrLf & vbCrLf
Next

'>go through all views:
For Each v In dbs.Views

sptext = v.Text

Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _
"************************************************* **************************
***"
& _
vbCrLf & vbCrLf & vbCrLf
Next

MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"

End Sub
Jul 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: markus | last post by:
This string does not work in php: $sql="UPDATE mytable SET myfield=myuserfunction(myfield)" What I want is my function to evaluate each field and put the new value in the field. For...
5
by: Ed Havelaar | last post by:
I have a cool function that I want to use as a default value for a column in my table. But I can't because apparently Access doesn't allow user defined functions in expressions for default values....
2
by: David Emme | last post by:
Access 97 I have a number of SELECT statements which contain references to user-defined VBA functions. These typically work as expected, but occasionally, on one user's machine or another,...
4
by: VivN | last post by:
I want to use an expression as the control source for a text box in a report (Access 2000). Whilst I have sucessfully used these simple ones =TimeToSingle(TotalHours(,))...
3
by: chreo | last post by:
I have user-defined function in MSSQL which returns Table (with 10 columns) (sorry for Polish names) CREATE FUNCTION PACZKI_Z_AKCJI (@AKCJA_ID int) RETURNS TABLE RETURN SELECT TOP 100...
1
by: Joel Dudley | last post by:
Hello, I am about to write a set of C functions to be used in an aggregate function in which the final function performs a calculation on an array of accumulated text data types stored in a text...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
4
by: Ara Kooser | last post by:
I am working on a text adventure game for python to get back into python programming. My version 0.1 used only functions so I could get familiar with how those work. I want to move beyond that. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.