[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-03-30
6
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 143

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 143

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

656 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