Use Stored Procedure developed in C# in a SQL Query

I created a Stored Procedure by selecting a SQL Server Project in Visual 
Studio 2008 using C#. It receives a SqlString as a parameter and return how 
many times a specific character was found. I deployed the procedure to a SQL 
Server database and can see it listed under the database. One caveat is that 
it has a small lock icon on it. 

I have a select query where I want to use the stored procedure. I am 
thinking this is doable in a select query but can't seem to get it to work. 
What I want to do is to have a select statement listing some fields and one 
of the fields being the stored procedure inputing one of the fields. Is that 
a proper use of C# stored procedure created in Visual Studio? Perhaps the 
lock icon has something to do with it. Any help in understanding the 
underlying mechanics would be greatly appreciated!

0
Utf
12/18/2009 9:45:01 PM
sqlserver.programming 1873 articles. 0 followers. Follow

4 Replies
1179 Views

Similar Articles

[PageSpeed] 45

You can't select from a stored procedure. You want to make a CLR UDF instead 
and then you can use it in the select.

-- 

Andrew J. Kelly   SQL MVP
Solid Quality Mentors

"Peter S." <PeterS@discussions.microsoft.com> wrote in message 
news:D75B06AB-FFD9-41D6-A9F7-B6C40208EF8C@microsoft.com...
> I created a Stored Procedure by selecting a SQL Server Project in Visual
> Studio 2008 using C#. It receives a SqlString as a parameter and return 
> how
> many times a specific character was found. I deployed the procedure to a 
> SQL
> Server database and can see it listed under the database. One caveat is 
> that
> it has a small lock icon on it.
>
> I have a select query where I want to use the stored procedure. I am
> thinking this is doable in a select query but can't seem to get it to 
> work.
> What I want to do is to have a select statement listing some fields and 
> one
> of the fields being the stored procedure inputing one of the fields. Is 
> that
> a proper use of C# stored procedure created in Visual Studio? Perhaps the
> lock icon has something to do with it. Any help in understanding the
> underlying mechanics would be greatly appreciated!
> 
0
Andrew
12/19/2009 2:19:56 AM
I understand, thanks. I did convert it to a UDF but it still doesn't seem to 
be recognized and is undefined. It did deploy it correctly and I can see it 
in the functions area but I can't seem to embed it in my SQL query. (Also CLR 
was set on using SQL). Do I have futher steps I need to do get it to be 
recognized?

"Andrew J. Kelly" wrote:

> You can't select from a stored procedure. You want to make a CLR UDF instead 
> and then you can use it in the select.
> 
> -- 
> 
> Andrew J. Kelly   SQL MVP
> Solid Quality Mentors
> 
> "Peter S." <PeterS@discussions.microsoft.com> wrote in message 
> news:D75B06AB-FFD9-41D6-A9F7-B6C40208EF8C@microsoft.com...
> > I created a Stored Procedure by selecting a SQL Server Project in Visual
> > Studio 2008 using C#. It receives a SqlString as a parameter and return 
> > how
> > many times a specific character was found. I deployed the procedure to a 
> > SQL
> > Server database and can see it listed under the database. One caveat is 
> > that
> > it has a small lock icon on it.
> >
> > I have a select query where I want to use the stored procedure. I am
> > thinking this is doable in a select query but can't seem to get it to 
> > work.
> > What I want to do is to have a select statement listing some fields and 
> > one
> > of the fields being the stored procedure inputing one of the fields. Is 
> > that
> > a proper use of C# stored procedure created in Visual Studio? Perhaps the
> > lock icon has something to do with it. Any help in understanding the
> > underlying mechanics would be greatly appreciated!
> > 
> .
> 
0
Utf
12/21/2009 7:43:01 PM
Peter S. (PeterS@discussions.microsoft.com) writes:
> I understand, thanks. I did convert it to a UDF but it still doesn't
> seem to be recognized and is undefined. It did deploy it correctly and I
> can see it in the functions area but I can't seem to embed it in my SQL
> query. (Also CLR was set on using SQL). Do I have futher steps I need to
> do get it to be recognized? 
 
What sort of function did you make it, scalar or table-valued? What does
your query look like?


-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

0
Erland
12/21/2009 11:09:27 PM
User-defined functions in SQL Server need to be called by using a 2-part 
name.
 select * from myfunction();   // does not work
 select * from dbo.myfunction(); // works, if the function lives in the dbo 
schema

SQL Server has two kinds of functions, table-valued functions which return a 
resultset (and there are 2 subcategories of those), and scalar functions, 
that return a scalar value.
 select * from dbo.my_tablevalued_function(parm1);
 select yourstring from dbo.your_tablevalued_function(parm1);  // one column 
TVF
 select dbo.my_scalar_string_function(parm1);  // it doesn't return a 
resultset, it returns a string

And BTW, the lock next to the icon in SSMS means "its a SQLCLR 
function/proc, you can't edit the source in SSMS (as you can with a SQL 
function/proc)"

Hope this helps,
Bob Beauchemin
SQLskills


"Peter S." <PeterS@discussions.microsoft.com> wrote in message 
news:4135349F-E88B-428D-86B0-350ABE8FD043@microsoft.com...
>
> I understand, thanks. I did convert it to a UDF but it still doesn't seem 
> to
> be recognized and is undefined. It did deploy it correctly and I can see 
> it
> in the functions area but I can't seem to embed it in my SQL query. (Also 
> CLR
> was set on using SQL). Do I have futher steps I need to do get it to be
> recognized?
>
> "Andrew J. Kelly" wrote:
>
>> You can't select from a stored procedure. You want to make a CLR UDF 
>> instead
>> and then you can use it in the select.
>>
>> -- 
>>
>> Andrew J. Kelly   SQL MVP
>> Solid Quality Mentors
>>
>> "Peter S." <PeterS@discussions.microsoft.com> wrote in message
>> news:D75B06AB-FFD9-41D6-A9F7-B6C40208EF8C@microsoft.com...
>> > I created a Stored Procedure by selecting a SQL Server Project in 
>> > Visual
>> > Studio 2008 using C#. It receives a SqlString as a parameter and return
>> > how
>> > many times a specific character was found. I deployed the procedure to 
>> > a
>> > SQL
>> > Server database and can see it listed under the database. One caveat is
>> > that
>> > it has a small lock icon on it.
>> >
>> > I have a select query where I want to use the stored procedure. I am
>> > thinking this is doable in a select query but can't seem to get it to
>> > work.
>> > What I want to do is to have a select statement listing some fields and
>> > one
>> > of the fields being the stored procedure inputing one of the fields. Is
>> > that
>> > a proper use of C# stored procedure created in Visual Studio? Perhaps 
>> > the
>> > lock icon has something to do with it. Any help in understanding the
>> > underlying mechanics would be greatly appreciated!
>> >
>> .
>> 

0
Bob
12/22/2009 12:19:20 AM
Reply:

Similar Artilces:

Can't insert Char(1) into SQL Server from Stored Procedure
Hello I am trying to insert a char(1) field into a table from an ASP.Net/C# application. At first I was inserting rows into the table but none of the columns that I was inserting the rows into were char(1) columns, they were mostly int and varchar columns. Then I found out that there was one column in the list that was not supposed to be an int column but instead it was supposed to be one of the char(1) columns into the table. So I replaced the int column in the list with the char(1) column and since the value of the char(1) column resulted from a CheckBox ('Y...

Changing SQL Server for CRM 1.2
As my SQL server is currently on its last breath I am in the process of moving our CRM 1.2 databases to a new dedicated serever. I have detatched the databases from the old server, copied the files to the server and attached them. I have then gone into CRM deployment manager and changed to the SQL server to the new server. That all appears to work fine, no error messages. But when users try to access the CRM system they get an error and the CRM server event log fills with error messages. A few are listed below: dmLog: Failed to execute the SQL batch in the file sqlbatch.sql. MSCRM P...

Business Portal Error-SQL server does not exist or access denied
Hi, We are running business portal 4.0 for one of our customer. It was running correctly, however, they have changed the SQL server port (previously it was set as default 1433). After that the business portal becomes very slow and while creating a new request (purchase requisition) if we open the item pop up; it is showing exception "SQL Server does not exist or access denied...." Can any body tell me how can I provide the new port number to business portal connection to the database. Thanks and Regards, Waliullah, Thanks for using the newsgroups. I have a...

Using mouse wheel in VB editor
Just tried using the mouse wheel to scroll within visual basic editor in excel but it wont let me. How can I turn this feature on. I am using Excel 2003. Thanks in advance. This is a known problem with the latest MS mouse drivers. You can either install version 4 of the drivers (current version is 5), or use FreeWheel, and freeware program at http://www.geocities.com/SiliconValley/2060/freewheel.html . -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "fullers" <fullers@discussions.microsoft.com> wrote in message ne...

Send to certain person using specific email account
I send an email to a certain receipient but don't want to use the default email account. Is it possible that when I send to them (plain text) , that it will choose the other account I want to use to send it? Please advise how I set this up. Thanks. I do not believe that this can be achieved automatically through standard use of Outlook as you need to manually specify the name of the account to send from if different than the default. However, it would be possible using the Outlook object model. An Addin would need to be developed that monitored each mail item prior to sending. If the d...

Web query timeout setting.
Dear Group, I fill an Excel table using data that I take from an Internet site. Unfortunately, this site is very slow and so I often get a "query did not provide any data" error message. How can I increment the default web query timeout limit? Thanks in advance, Enrico. ...

Use exchange from a trusted domain
Hi folks, I have domain a and domain b. Domain a is all set upp with exchange etc. Domain b was bought, and they don't have exchange. I have trust between the domains and file sharing and authentication are ok. What we want to do is, make users on domain b and let them use the exchange (on a seperate storage) on domain a. The users on domain b must logon to domain b, but need to have mailbox on domain a. Domain a are running on win2003 and exchange 2003. Domain are running on win2003 with forest and domain ready for exchange. Any advices? thanks in advance, - Bjarni Hi, Thi...

Using Access 2003 on client to see Sharepoint 2007
Testing a Sharepoint environment and I can easily manipulate and run the database from Access 2007, but when I try to use Access 2003 it wants me to save the database to a location. The Access 2003 has the compatiblity pack, but it seems to not work when I download it. So the question is using Sharepoint 2007 and posting the Access 2007 format to it, can a user go to the sharepoint site and use a 2003 Access database that has the compatibility pack and open without having to download it? -- Message posted via http://www.accessmonster.com Send check for $500.00 to: David A Jenn...

SQL View with Smartlist Builder
I am having to recreate Anyviews (GP8) into Smartlists (GP10SP3). Not very happy. Many of our Smartlist require the use of SQL views do to the limitations of Anyview and now Smartlist. It appears that I must create a separate Smartlist for each company I wish to use my sql view with. Is there not a way to include a custom SQL view in Smartlist, and have Smartlist use the company the user is logged into? The view exist in each company database. Can this be done with SQL Reporting server and DynamicsGP? Can I pull a report based on the company db the user is logged into? Thanks for the...

How Use ShellExecute with a CMemFile
Hello, I need to store files of various types (such as .doc, .xls, .jpg, .pdf, ..wmv, ...) in a database. Upon retrieval of such a file I have the file as data in memory in a CMemFile. I need to then "display" the file in the aproriate application. If I were to write the CMemFile to disk and create an actual file I could then, of course, use ShellExecute() to launch , say Word to display a .doc file. However, I would much prefer to avoid the overhead of writing the data to an actual file and then dealing with having to detect when the User is done and cleaning up the file I had ...

Visual C++ 2005 always rebuilds
I have an MFC DLL project that I recently moved over to Visual Studio 2005. However now the project always rebuilds entirely whenever I start debugging. Even if I have only made a simple change to one file. Any help would be greatly appreciated. Thanks Colin Check the date on your source files to make sure that they are not in the future. AliR. "Colin J Paterson" <nospam@thanks.com> wrote in message news:ObtLxgTbGHA.1196@TK2MSFTNGP03.phx.gbl... > I have an MFC DLL project that I recently moved over to Visual Studio 2005. > However now the project always rebuild...

Can i use conditional formating on a cell when it contains a formula?
I am trying a "conditional formatting" on a cell that contains formula, but it didn't work. "If cell value is equal to 0 then font - white" This doesn't work, stays always. If i use this condition on a cell without formula it works just fine. Thank -- si ----------------------------------------------------------------------- sit's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=262 View this thread: http://www.excelforum.com/showthread.php?threadid=26784 Hi are you sure your formula returns an exact zero?. Could you post the formul...

Using INDIRECT within functions
I learned a bit from JLathman in a previous post but tried to use the same methodology with this formula (also learned from this Group to get the last entered value in a column) without much luck. The original formula was this with 2009 sheet being static: =LOOKUP(2,1/('2009'!H3:H65536<>""),'2009'!H3:H65536) Trying to make it dynamic I tried the following without success: =LOOKUP(INDIRECT("2,1/(" & O1 & "!$H$3:$H$65536<>"")," & O1 & "!$H$3:$H$65536)")) Did I miss something or are...

Outlook to SQL
The problem is this I'm trying to get my Contact list that was created on a Exchange Server to a SQL table. How do I do this with keeping the Database created in SQL up-to-date via Outlook. See http://www.outlookcode.com/d/database.htm and = http://www.slipstick.com/addins/groupcontacts.htm for tools to help with = this.=20 --=20 Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for=20 Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "ErikSQLConfuser" <ErikSQLConfuser@discussions.microsoft.com...

convert to stored proc
Hello. I have been given a conversion assignment to convert Access db (frontend) with sql server 2005 backend to be included in a new webapp that is being constructed. Unfortunately, my stored proc creating is a bit weak and I'm not afraid to admit it. With that said, I came across an Access query that is puzzling me. Here it is; SELECT Purchase Orders *, POSO Relationships.SONumber AS RelatedSONumber, IIf([POSOType], [POSOType], 'Standard') AS POSOTypeFull, POSORelationships.MTXRMA, POSORelationships.SupplierRMA, POSORelationships.POSOType FROM PurchaseOrders ...

How to use count for calls per hour
I am trying to create a pivot table and chart that will show me the # of calls per hour by day for a range of dates Aug 1 - Sept 19. My data looks like this where each line is the date and time of the call: How do I get a count of the # of the calls per hour by day? 8/1/08 12:48 AM 8/1/08 1:53 AM 8/1/08 2:36 AM 8/1/08 3:24 AM 8/1/08 3:37 AM 8/1/08 4:04 AM 8/1/08 4:44 AM 8/1/08 4:55 AM 8/1/08 4:58 AM 8/1/08 7:02 AM 8/1/08 7:28 AM 8/1/08 7:43 AM 8/1/08 7:47 AM 8/1/08 7:56 AM 8/1/08 7:58 AM 8/1/08 8:13 AM 8/1/08 8:33 AM 8/1/08 9:07 AM 8/1/08 10:28 AM 8/1/08 10:38 AM 8/1/08 10:44 AM 8/1/08 ...

How export all mailbox-enabled users from the GAL using Outlook?
Hello, We have a user which, for administrative reasons, needs to export all mailbox-enabled users in the GAL now and then. They just need all the names. Is there a straightforward way for them to do that? We don't want to give them any special permissions and want to avoid server scripting. Ideally, they should be able to export it to a CSV file or any text file. Thanks, - Alan. Alan wrote: > We have a user which, for administrative reasons, needs to export all > mailbox-enabled users in the GAL now and then. They just need all the > names. Is there a straightforward way fo...

SQL query / Formula for Reorder Point?
Is it possible to issue an SQL command(s) that would: 1. Set the Restock Level for all items to be equal to the current on-hand quantity for each item. 2. Set the Reorder point for all items to be equal to 1/3 of that items Restock Level. I'm currently doing this manually, or using a formula in excel when items are initially imported into the DB, but there are still several thousand that need to be retro-fitted like this... Thanx in advance! -=RFM=- UPDATE Item SET RestockLevel=(Quantity - QuantityCommitted) UPDATE Item SET ReorderPoint=ROUND(RestockLevel/3,0) - Evan Culver Ne...

SQL 2008 running on a VM using all allocated memory
Hi, I've got a sql2008 server running on a VM. There's 9GB of physical RAM, which 7GB have been allocated to SQL Server. But when i look at task manager, i see that the SQL server is actually using all 7GB, which is pegging the memory usage of the overal box at above 90% used. We're mostly a sql2005 shop, and none of those servers are doing this. I have sql2005 running on VM's, someone actual servers as a named or default instance, and some even clustered. None of them have this problem. Is this a normal thing with sql2008 only? Any insight would be greatly appre...

Anyone use Promys CRM software integrated with GP Dynamics?
Our company is considering using Promys as a CRM to create quotes and sales orders for the sales team. I am concerned about the integration with GP and what the pitfalls may be. Is anyone here currently using Promys with GP Dynamics? ...

Loading Text File to TextBox using LoadFromFile
Hi All, I'm creating a form that allows the user to pick a txt file (dialog) and then display the path and contents on the form. The code has been cobbled together as I found the pieces that worked, so bear with. I got the file picker working and displaying the file name on the form, but the file contents won't display. I had a feeling the problem had to do with importing a namespace (see the error in the code when I tried "Imports System.IO") or with a missing reference. Using Access 2003. References: VB for Apps, MS Access 11 Obj Lib, OLE Auto, MS V...

Can't use openURL or access internet on some locations
I have previously raised a question where openUrl threw an exception in a specific office location. However the problem I have now is that the application just freeze when I call openURL. It seems as it is waiting for something. This only happens at one company so far the company does have a proxy but so do I at work and I have no problems. I have also tried the Microsoft TEAR sample and it behaves the exact same way, it says "Opening internet...Connection made" and then it just stops. If I run it on my computer it gets the webpage and everything finishes ok. I have tried to set t...

Query involving Strings : How To Return Matching Data From Both Ta
Good afternoon, I have tried my best on this but am unable to figure it out. --------------------------------------------------------------------- Scenario: Table A contains only one column titled [District]. Let's assume that there are three rows here: 1) Bay Area Rapid Transit 2) San Diego Zoo 3) San Mateo Table B contains other data with these fields: [GeoCode] , [CountOfHourlyEmployees], [CountOfSalaryEmployees]. Let's assume that there are three rows here: 1) West Coast | CA | Bay Area Rapid Transit , 154, 205 2) CA | Southern | Bay Area Rapid Transit , 105, 206 3) Southw...

Store.exe processes
Every morning I check my exchange 5.5 mail server I notice that Store.exe processes is using over 50% of CPU time. This continues and when user try start to logon the server becomes unavailale and the requires a restart. I have applied various patches that microsoft recommended and it still doesn't help. When the server crashes it logs error "Background Cleanup" "event 1101". Microsoft suggestions doesn't work. If anyone ever had this problem please let me know your course of action to resolve the issue. ps. Once rebooted, the server runs all day with an issu...

unable to send outbound mail using outlook
I've enabled the smtp virtual server on our new exchange server and have our domain's mx record pointed to it. I've redirected our clients to point from our ISP's mail server to ours, but outbound mail is not working. when i tried to telnet to our server and do a "mail from: " of a local account, it's saying invalid address. Is there a separate setting to enable using this SMTP virtual server for outgoing mails? -Jerry Sorry... my mistake. I simply enabled message relaying and it works now. "jerrydy" wrote: > I've enabled the smtp virtua...