Store The Output Of Sp_executesql - Solved With Managed Code
Apr 18, 2006
hi
I am trying to store the output of sp-executesql into a variable to implement it as a user defined function later
The function is
ALTER function [dbo].[UnitsAvailable] (@id int)
returns int
as
begin
declare @sql nvarchar(100)
declare @params nvarchar(500)
declare @count nvarchar(10)
set @sql = N'Select count(*) from units where projectid=' + convert(varchar,@id) + 'and sold=0 and displayunit=1'
set @params = N'@countOUT nvarchar(10) OUTPUT';
exec sp_executesql @sql, @params, @countOUT=@count OUTPUT;
return @count
end
The result is that I am able to parameterize the sql end execute with the right result. The only problem is that the value is not stored in the variable @count. I could get to the same result using managed code in sql 2005 but still I am curious to find out where the problem is ....
Can you please help?
Thanks Alex
View 6 Replies
ADVERTISEMENT
Sep 14, 2006
Is there a way to supress output on one column in a SP, using data from the same row?
Like This:
SELECT Last, First, DOP, dbo.fnDueDate(DOP, 3, GETDATE()) AS NextQDue, dbo.fnDueDate(DOP, 6, GETDATE()) AS NextNSPDue, DATEADD(m, 1, DOP)AS InitialNSPDue, DATEADD(m, 1, DOP) AS InitialAssessDue, DOT, DisReason, DATEADD(m, 1, DOT) AS DisSummDue, Facility, Active
FROM dbo.tblResidents
But which returns null for some of the columns if DOT is not null?
DOT is the Termination Date, so the only columns that have any meaning once there is data in the DOT column are DisReason and DisSummDue. Also, if DOT *is* null, then the above columns also have no meaning.
I tried several variations of the following, but I can't figure it out
CREATE PROCEDURE [dbo].[spTesting] AS
BEGIN
SELECT Last, First, DOP, dbo.fnDueDate(DOP, 3, GETDATE()) AS NextQDue, dbo.fnDueDate(DOP, 6, GETDATE()) AS NextNSPDue, DATEADD(m, 1, DOP) AS InitialNSPDue, DATEADD(m, 1, DOP) AS InitialAssessDue, Facility
FROM dbo.tblResidents A
WHERE DOT IS NULL
UNION
SELECT Last, First, DOP, DOT, DisReason, DATEADD(m, 1, DOT) AS DisSummDue, Facility
FROM dbo.tblResidents I
END
GO
----------------
-Stephen
View 4 Replies
View Related
Sep 4, 2007
I have created a managed stored procdure in a sql server project in VS. I have put in the corect server name password and login fro the connection to the database.
When I deploy however it doesn't deploy the stored proccdure to the database even though it says it has successfully deployed the stored procedure. Has anyone had this
problem and how can you make sure it is deploying to the correct database.
View 1 Replies
View Related
Apr 11, 2007
Can anyone explain to me why I would choose one over the other? Please provide some simple examples of when I would choose each. Thanks!
View 4 Replies
View Related
Nov 20, 2006
I have a SQL Server project in Visual Studio 2005 which deploys an assembly to SQL Server 2005 containing various stored procedures user defined functions. Is there any way to tell Visual Studio to drop/create the stored procedures in a schema other than dbo?
ie: User.ChangePassword instead of dbo.ChangePassword.
View 2 Replies
View Related
Aug 24, 2007
Hi there,
Values in my database need to updated periodically. The code, upon starting the application, queries the database and stores the values in the Application collection. This is to avoid making a database call everytime the values are needed (increases performance). The drawback is that changes to the database values are not updated in the code.
How can I create a database trigger that will update the C# Application colllection whenever a table value is updated?
View 2 Replies
View Related
Apr 19, 2007
There is an interesting article from MSDN Magazine titled "Identify and Prevent Memory Leaks in Managed Code"
http://msdn.microsoft.com/msdnmag/issues/07/01/ManagedLeaks/default.aspx
Are there any additional documents or utilities that people would suggest for monitoring and managing CLR impact on SQL server resources and performance?
View 1 Replies
View Related
Oct 3, 2006
I have been attempting to create a managed stored procedure which calls a web service using WSE 3.0 for security.
It appears that the WSE-generated config file (or possibly the app.config file) is not accessible to the .Net code.
Is there a method for using config files with CLR managed sprocs?
Thanks,
Max
View 1 Replies
View Related
Jan 10, 2007
Hi everyone,
Primary platform is Framework 2.0
Our current service throws on-demand .DTSX and now we'd like that will throw old ETL 2000 too.
I'd like to know if success or not success when calling dtspkg.dll from my managed code (vb).
Is it possible or not? I only capture errors for the sake of TRY..END TRY but I don't know how the hell to know
if the dts execution was successful.
Execute method not returns anything.
Currently my schema is the following:
paquete = New DTS.Package2
paquete.LoadFromSQLServer("SRVDESA1", , , DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, _
, , , "pruebaenric")
paquete.FailOnError = True
Try
paquete.Execute()
Catch ex As Exception
' stuff
End Try
paquete = Nothing
I've tried to use WITHEVENTS but it's useless at all from there.
Events are not fired. I though that RCW created for this could be able to call them...
Private Withevents paquete as dts.package2
Private paquete_OnError()
stuff
Private paquete_OnProgress()
stuff
Thanks for any input related with,
View 3 Replies
View Related
Mar 6, 2008
Hi all( Create a VB 2005 SQL Server Project )
i want to Create a Trigger using Managed Code in VB.Net (.NET CLR integration with SQL Server.)Somebody help me.Thanks
View 2 Replies
View Related
Aug 22, 2004
I am trying to debug sql2000 sp from managed code app with VS.Net 2003 archetect Ed..
It did not stop at the break point within the sql sp.
I did granted execute permission for sp_sdidebug.
Do I need to attach any process?
Is there anything left off by the article?
I referenced msdn article option 2: http://support.microsoft.com/default.aspx?kbid=316549
Thanks.
View 3 Replies
View Related
Jan 23, 2008
Hi,
I have a requirement to create #Temp table in database and insert values to it.
I use following code:
DbCommand dbCreateTable;
dbCreateTable = provider.CreateCommand();
dbCreateTable.Connection = conn;
dbCreateTable.CommandText ="Create table #MyTemp (Id varchar(10))";
dbCreateTable.ExecuteNonQuery();
string[] insertValues = {"Insert into #Mytemp values ('TestString1')",
"Insert into #Mytemp values ('TestString2')"};
DbCommand dbInsertData = provider.CreateCommand();
dbInsertData.Connection = conn;
foreach (String insertStr in insertValues)
{
dbInsertData.CommandText = insertStr;
dbInsertData.ExecuteNonQuery();
}
Code creates the Temp table but when it comes to insert statement, it throws error saying "Temp table not found".
Reason can be Create and Insert statement gets executed as 2 different sessions.
How to get the above requirement work fine?
Thank you.
HV
View 4 Replies
View Related
Mar 11, 2008
All --
Please help.
I am using managed code in SQL Server 2005 and have a question about stored procedure name qualification.
With a VS.NET 2005 Pro Database project, when I use >Build, >DeploySolution, it works great but my stored procedures are named with qualification using my domainusername.ProcName convention, something like this...
XYZ_TECHKamoskiM.GetData
...when I want them to be named with the dbo.ProcName convention, something like this...
dbo.GetData
...and I cannot see where this can be changed.
Do you happen to know?
Please advise.
(BTW, I have tried going to this setting >Project, >Properties, >Database, >AssemblyOwner, and putting in the value "dbo" but that does not do what I want.)
(BTW, as a workaround, I have simply scripted the procedures, so that I can drop them and then add them back with the right names-- but, that is a bit tedious and wasted effort, IMHO.)
Thank you.
-- Mark Kamoski
View 1 Replies
View Related
Aug 4, 2006
Dear friends,
please help,
let me tell you what happens,
1) first i installed Sql Server 2005 Enterprise Edition, everything was working fine except i was not able to create managed objects from BI, like stored procedures, triggers, UDT, etc etc.
2) so i installed VS.net 2005 complete + Sql Server 2005 Express Edition
now i was able to create stored procedures, triggers, etc etc, i'm talking about the CLR objects, ok, i.e. the managed code, but........ i was only able to do this from Sql Server 2005 Express Edition.
whenever i try to create managed objects CLR like stored procedures and stuff from the Sql Server 2005 Enterprise edition it gives me the following error :
"The Sql Server supplied by these connection properties, does not support managed code, please choose a different server"
please help meeeee.. please please, tell me what's the problem ?
below i'm attaching a screenshot of the error....
View 3 Replies
View Related
Mar 17, 2006
I cannot get my output parameter to output... It comes up as NULL!
I Pass in @NumFound as an OUTPUT Parameter as follows
...@NumFound INT OUTPUT
AS...
Then I build the where clause which I know is working properly because it is used in another sp_executesql statement which is returning the correct results. Then I do this to get a total count of the records found, and I get nothing back...
SET @l_ParamDef = N'@PType nvarChar(50),@Client nvarChar(50),@City nvarChar(50),@ApptDate nvarChar(50),@OrderDate nvarChar(50),@Status nvarChar(50),@AType nvarChar(50),@Text nvarChar(50),@PageSize INT,@l_TotalRecords INT,@NumFoundOut INT OUTPUT'
SET @l_CountSql = 'SELECT @NumFoundOut = COUNT(*) FROM Orders As o' + @l_Where
EXEC sp_executesql @l_Sql, @l_ParamDef, @PType, @Client, @City, @ApptDate, @OrderDate, @Status, @AType, @Text, @PageSize, @l_TotalRecords, @NumFoundOut = @NumFound OUTPUT
Thank You,
Jason
View 1 Replies
View Related
Sep 4, 2007
can somebody let me understand how this Output parameters works in sp_executesql / Dynamic TSQL
I want to store a integer value resulting from executing a dynamic query. I was trying to follow the syntax but to be honest I didn't get it, and resulted in err. So can somebody help me in understanding how it works and how and where to declare the variables to be output and what command does that Output etc.
Thanks a lot in advance
View 4 Replies
View Related
Aug 17, 2006
Dear all,
I am very new to the subject of writing CLR code inside SQL Server, so I apologise if my questions seem naive.
I have a requirement to populate an asp.net 2.0 GridView control with data columns, some of which are directly from a SQL Server 2005 database, but some of which are calculated by calling CLR methods passing the values from the database columns to those methods.
However, the methods I need to call only make sense in the process context of the client web site which is calling the stored procedure which I want to write to return the data columns.
In effect, I want to be able to make a remote procedure call from within the SQL Server CLR code to the methods available in the client process.
Is this possible? If so, could someone please refer me to an example of how to do it.
If it can be done, it opens up lots of very cool possibilities!
Thanks.
View 3 Replies
View Related
Oct 24, 2007
Hi All,
We seem to have an problem with using sp_executesql and retrieving back NVARCHAR output parameters. We are trying to dynamically set string values using string templates ( for English and other languages that require using NVARCHAR parameters ). A test case is:
DECLARE @Description NVARCHAR(400)
DECLARE @Template NVARCHAR(400)
SET @Template = N'''ПричинÑ?ет ''' -- this string is in Russian
SET @Template = N'SET @DescriptionOUT = ' + @Template
EXEC sp_executesql @Template, N'@DescriptionOUT NVARCHAR(4000) OUTPUT', @DescriptionOUT = @Description OUTPUT
PRINT @Description
If you print @Description it appears as: ????????? instead of the Russian text.
Any thoughts or ideas on why this isn't working as the BOL indicate that everything should correctly handle NVARCHARs?
Thanks.
Robert
View 5 Replies
View Related
Sep 21, 2015
Inside some TSQL programmable object (a SP/or a query in Management Studio)I have a parameter containing the name of a StoreProcedure+The required Argument for these SP. (for example it's between the brackets [])
EX1 :Â @SPToCall : [sp_ChooseTypeOfResult 'Water type']
EX2 :Â @SPToCall : [sp_ChooseTypeOfXMLResult 'TABLE type', 'NODE XML']
EX3 :Â @SPToCall : [sp_GetSomeResult]
I can't change thoses SP, (and i don't have a nice output param to cach, as i would need to change the SP Definition)All these SP 'return' a 'select' of 1 record the same datatype ie: NVARCHAR. Unfortunately there is no output param (it would have been so easy otherwise. So I am working on something like this but I 'can't find anything working
DECLARE @myFinalVarFilledWithCachedOutputÂ
NVARCHAR(MAX);
DECLARE @SPToCall NVARCHAR(MAX) = N'sp_ChooseTypeOfXMLResult
''TABLE type'', ''NODE XML'';'
DECLARE @paramsDefintion = N'@CatchedOutput NVARCHAR(MAX) OUTPUT'
[code]...
View 3 Replies
View Related
Jul 23, 2005
Greetings All, I have a very large query that uses dynamic sql. Thesql is very large and it requires it to be broken into three componentsto avoid the nvarchar(4000) issue:SET @v_SqlString(N'')SET @v_SqlString2(N'')SET @v_SqlString3(N'')The sql is large and I don't have a problem with that so I will notpost it. However, in the last string the very last statement lookelike:SET @v_SqlString3(N'......SELECT @v_TotalRowsLoaded = @@ROWCOUNT, @v_ExitStat =@@ERROR')I want to catch this output and I am having problems, here is what myexecute looks like:EXEC('DECLARE @v_TotalRowsLoaded integerDECLARE @v_ExitStatus integerEXEC sp_executesql N''' + @v_SqlString + @v_SqlString2 +@v_SqlString3 + ''',N''@v_TotalRowsLoaded integer OUTPUT'',@v_TotalRowsLoaded OUTPUT,N''@v_ExitStatus integer OUTPUT'',@v_ExitStatus OUTPUT,N''@v_OLTPQualifiedPath nvarchar(1000)'',@v_OLTPQualifiedPath = ''' + @v_OLTPQualifiedPath + ''',N''@v_LoadTime datetime'', @v_LoadTime =''' + @v_LoadTime + '''')When I run it as is I am prompted with:Server: Msg 119, Level 15, State 1, Line 126Must pass parameter number 8 and subsequent parameters as '@name =value'. After the form '@name = value' has been used, all subsequentparameters must be passed in the form '@name = value'.You are required to pass five "5" arguments.Can anyone tell me why this is failing? What can I do?Any help would be greatly appreciated.
View 7 Replies
View Related
Apr 2, 2008
Hi everyone
I try to run Dynamic sql wherby sp_executesql as follows:
Code Snippet
DECLARE @params NVARCHAR(4000)
DECLARE @portion INT
SET @portion=6
DECLARE @mydynamic NVARCHAR(4000)
SELECT @mydynamic = ' SELECT TOP @portion * FROM server.database.dbo.mytable'
SELECT @params = N'@portion INT '
EXEC sp_executesql @mydynamic,@params, @portion
I get the following error message:
Code Snippet
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '@portion'.
Any idea what is wrong with that code?Thanks
View 6 Replies
View Related
Feb 10, 2006
I am trying to understand creating SQL Server projects and managed code. So I created a C# SQL Server Database project and named it "CSharpSqlServerProject1" and followed the steps in the following "How to: " from the Help files:
"How to: Create and Run a CLR SQL Server Stored Procedure "
I used the exact code in this "How to: " for creating a SQL Server managed code stored procedure (see below) in C#. However it didn't even compile! When I went to build the code I got the following error message:
"Error 1 Target string size is too small to represent the XML instance CSharpSqlServerProject1"
It does not give a line number or any further information! Since this is a Microsoft example I'm following I figure others must have run into this too. I can't figure out how to fix it!
Here's the code as copied directly from the howto:
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[SqlProcedure()]
public static void InsertCurrency_CS(
SqlString currencyCode, SqlString name)
{
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
SqlCommand InsertCurrencyCommand = new SqlCommand();
InsertCurrencyCommand.CommandText =
"insert Sales.Currency (CurrencyCode, Name, ModifiedDate)" +
" values('" + currencyCode.ToString() +
"', '" + name.ToString() +
"', '" + System.DateTime.Now.ToString() + "')";
InsertCurrencyCommand.Connection = conn;
conn.Open();
InsertCurrencyCommand.ExecuteNonQuery();
conn.Close();
}
}
}
Thanks for any help you can give!
View 7 Replies
View Related
Feb 24, 2006
naturale02 writes "Here is my SP:
CREATE procedure test as
select top 10 count (*) as Download, a.item_code as Item_Code, b.item_title as Item_Title
into report..ten
from tbl_statistics_archive a , shabox..tbl_items b
where a.item_class = '10'
and convert(char(10),a.created,111) >= convert(char(10),getdate()-7,111)
and convert(char(10),a.created,111) <= convert(char(10),getdate()-1,111)
and a.item_code = b.item_code and a.item_class = b.item_class
group by a.item_code, b.item_title
order by 1 desc
GO
I have create the table called 'ten', and i schedule this SP, but when i start the job, there was nothing shown on 'ten' table, which part i have been doing wrong, kindly help me.
Thank you"
View 1 Replies
View Related
Mar 26, 2008
This is my stored procedure .It is working fine .I want to capture the output in a print statement .Can anyone help me please .
alter proc r (@id INT)
as
BEGIN
DECLARE @input VARCHAR(800)
DECLARE @c_input INT
DECLARE @i_Input INT
DECLARE @input_left VARCHAR(800)
DECLARE @delimiter CHAR(1)
select @delimiter = ','
DECLARE @in VARCHAR(800)
DECLARE @list VARCHAR(800)
declare @list2 VARCHAR(800)
SET @input = 'AWCA,GCS,IHP,Aetna'
select @c_input = (select dbo.Fx_CharCount(@delimiter,@input))
set @c_input = @c_input + 1
while @c_input > 0
BEGIN
select @i_input = charindex(@Delimiter,@input)
if @i_input != 0
BEGIN
select @input_left = left(@input, @i_input - 1)
END
else
select @input_left = @input
select @in = '''' + @input_left + ''''
select @list = ISNULL(@list + ',', '') + @in
select @input = right(@input ,(len(@input) - @i_input))
SET @c_input = @c_input -1
if @c_input = 0 or @input = @input_left
break
end
Print @list
EXECUTE ('SELECT Label FROM repricingsystemtype WHERE Label Not IN (' + @list + ')')
END
View 5 Replies
View Related
Apr 16, 2007
Just getting started with SQL Server CLR integration. Any suggestions on how to organize code? Should I keep my CLR Stored Procedures in a separate project than the code that will call them? Should each DB have its own project containing all the CLR code?
Maybe there is no right way...I'm just looking for a good way.
Thanks!
View 3 Replies
View Related
Jun 4, 2008
I have the following Query which gives the output in XML format.
select * from <Table_Name> For XML auto
I wanted to store this output in a .Xml file at my local machine.
I would prefer to have a proc when called generates the xml and stores it on the local m/c. Any ideas ?
Thanks,
View 3 Replies
View Related
Nov 19, 2003
In SQL Server SP theres a stored procedure called ProductDetail.
What is the OUTPUT parameter for?
What does it do?
thanks
CREATE Procedure ProductDetail
(
@ProductID int,
@ModelNumber nvarchar(50) OUTPUT,
@ModelName nvarchar(50) OUTPUT,
@ProductImage nvarchar(50) OUTPUT,
@UnitCost money OUTPUT,
@Description nvarchar(4000) OUTPUT
)
AS
SELECT
@ProductID = ProductID,
@ModelNumber = ModelNumber,
@ModelName = ModelName,
@ProductImage = ProductImage,
@UnitCost = UnitCost,
@Description = Description
FROM
Products
WHERE
ProductID = @ProductID
GO
View 11 Replies
View Related
Jan 24, 2006
I'm trying to use a store procedure to add an item into the database and retrieve the id of such item within and output parameter but this is not happening.
The item is added into the db but the output param is not modified.
Here is the code:
SP
CREATE procedure dbo.AddItem(@Desc nvarchar(100),@intItemID int output)as insert into RR_Item ( desc ) values ( @Desc )
select @intItemID = SCOPE_IDENTITY()GO
I have tried in the last line of the SP
select @intItemID = SCOPE_IDENTITY()
select @intItemID = @@IDENTITY
select @intItemID = max(itemid) from RR_Item
but nothing seems to work.
I'm calling the store procedure as follows from asp.net:
Dim intItemID As New SqlParameter("@intItemID", SqlDbType.Int)
intItemID.Direction = ParameterDirection.Output
SqlHelper.ExecuteDataset(objConn.ConnectionString, "AddItem", desc, intItemID)
MsgBox(intItemID.Value.ToString)
Any help would be appreciated.
Thanks
View 1 Replies
View Related
Jan 23, 2004
How do I call capture the output (not return value) from calling a store procedure from within a store procedure so I can use that data for further processing (say join it with another table)?
For example,
CREATE PROCEDURE dbo.sp_test AS
--- returns all words not in Mastery Level 0
EXEC sp_anothertest
--- use the data coming back from sp_test and join it with another table here and say insert them into tblFinalResults
SELECT * tblFinalResults
GO
Thanks!
View 1 Replies
View Related
Oct 10, 2007
ex:
myprocedure(@Cusname varchar(50), @Cusid int output)as
Insert into Customer(Cusname) values (@Cusname)SELECT @cusid = @@IDENTITY
i add the query to my adapter called CreatCustomer (@Cusnam,@Cusid)private Merp_CusListTableAdapter _CuslistAdapter = null;protected Merp_CusListTableAdapter Adapter
{
get
{if (_CuslistAdapter == null)
_CuslistAdapter = new Merp_CusListTableAdapter();return _CuslistAdapter;
}
}
Now how i write function in BLL to receive output paramter from creatcustomer function?
View 1 Replies
View Related
Oct 22, 2005
Hi all,Could someone give me an example on how to create and execute the store procedure with using output parameter?In normal, I create the store procedure without using output parameter, and I did it as follow:CREATE PROC NewEmployee (ID int(9), Name Varchar (30), hiredate DateTime, etc...)ASBEGIN //my codeENDGOWhen i executed it, I would said: Execute NewEmployee 123456789, 'peter mailler', getDate(), etc....For output parameter:CREATE PROC NewEmployee (ID int(9), Name Varchar (30), hiredate DateTime, @message Varchar(40) out)ASBEGIN insert into Employee ...... //if error encountered set @message = "Insertion failure"ENDGOExec NewEmployee 123456789, 'peter mailler', getDate(), do I need to input something for the output parameter here?Anyone could give me an example on how to handle the output parameter within the store procedure coz I am not sure how to handle it?Many thanks.
View 1 Replies
View Related
Feb 14, 2007
Hi
I have designed a package that reads in rows from an Excel file into a recordset then loops through the recordset sending two parameters to a webservice task. This works fine however I now need to output the results of the webservice task to a file or recordset - I have tried outputting to a file however it only stores the last result as the file is overwritten each time - I am new to SSIS and am sure there must be a really simple way to do this but cannot find an help on how to do it !
Thanks in advance K
View 4 Replies
View Related
Jun 12, 2007
Hello Frdz, I have doubt regarding the datatypes fields used in SQL SERVER 2005.I want to use the field to store the mobile number of the user .Which datatype should i used ?? The value for bigint Int64 is 18The value of int Int32 is 9/10Now,if in int i write : 1234567890 (accepted)This gives error : 9874565656 (not accepted..........why is it so ??? )Why is it so ??I want to know the perfect size of all the datatypes used in SQLSERVER 2005.There are also smallint,tinyint.....What's the main difference with all of them ??Can anyone provide me the nice links which can explain me what m i asking in this post...Please help me....I want to know all the datatypes used differences...
View 1 Replies
View Related