Solved

What is the difference between a VBA function and a SQL Server function?

Posted on 2009-03-30
6
262 Views
Last Modified: 2013-11-27
What is the difference between a VBA private/public function and a SQL Server function?

I'm jumping from Access to SQL Server and VBA to C# sharp now.
In the past when I had an update query I could do the following SQL -

UPDATE tblColTypes SET tblColTypes.Family = Replace_Symbols([Family])
WITH OWNERACCESS OPTION;

And the Replace_Symbols would be in a VBA module as:

Public Function Replace_Symbols(sVlu As String) As Variant
On Error GoTo Err_This
 
  sVlu = Replace(sVlu, "-", "")
  sVlu = Replace(sVlu, "/", "")
  sVlu = Replace(sVlu, Chr(34), "")
 
  Replace_Symbols = sVlu
 
Exit_This:
    Exit Function
   
Err_This:
    Resume Exit_This
End Function

How would I do this in C# using Visual Studio 2008 - do I create a SQL Server function in under my Server Explorer window?
0
Comment
Question by:stephenlecomptejr
  • 3
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24023786
yes, a function would do:
create Function dbo.Replace_Symbols(sVlu as varchar(max) ) returns varchar(max)
as 
begin
 set @sVlu = replace(@sVlu, '-', '')
 set @sVlu = replace(@sVlu, '/', '')
 set @sVlu = replace(@sVlu, '''', '')
 reutrn @sVlu 
End 

Open in new window

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24023802
2 notes:

? the functions are created "per database", so make sure you are connected to the correct database when creating the function.
? to use the function in the sql code, you need to prefix with the owner name (dbo.) like in the create:

select dbo.Replace_Symbols('123-456/789''0') data

Open in new window

0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 24023806
I would suggest taking a look at LINQ ... since you are making a fresh start

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx


0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 24023869
I get an error - Incorrect syntax near 'sVlu'
Must declare the scalar variable "@sVlu"
Must declare the scalar variable "@sVlu"
Must declare the scalar variable "@sVlu"
ok

I'm doing this inside of Visual Studio 2008 - under Server Explorer - under Database.mdf - Add New Functions...
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24023931
sorry:
create Function dbo.Replace_Symbols(@sVlu as varchar(max) ) returns varchar(max)
as 
begin
 set @sVlu = replace(@sVlu, '-', '')
 set @sVlu = replace(@sVlu, '/', '')
 set @sVlu = replace(@sVlu, '''', '')
 reutrn @sVlu 
End 

Open in new window

0
 
LVL 1

Author Closing Comment

by:stephenlecomptejr
ID: 31564568
Yea - Thank you sincerely!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question