How To Return A String Value From The Store Procedure

Jun 3, 2008

Hi All,

I have to return a string value from the store procedure.
If condition success
    BEGIN
        RETURN 'Success'

     END
ELSE
   BEGIN
        RETURN 'Fail'

   END
I am retrieving this value with ExecuteReturnQuery() method. But it gives me the error like "Conversion failed when converting the varchar value to data type int."
can anyone please help me for this?
Thank you.
Regards.
 

View 5 Replies


ADVERTISEMENT

Return String From Store Procedure?

Aug 14, 2006

How can i do ?
It's always display error : "Can' not convert nvarchar to int"
Thank you very much.

View 8 Replies View Related

Store Procedure Can Return More Than One Value?

Dec 8, 2005

Can the store procedure can return more than one value? If i need to return 2 values, how to do that??

View 1 Replies View Related

Return From Store Procedure.

Sep 12, 2005

Dear All, I read through all the post and flipped through the books but Istill can't find the answer to my problem.I'm inserting a new record via a stored procedure and want to return the idvia scope_identity, which I thought would be preety straight forward.The code I'm using is below and this keeps giving me "Multiple-step OLE DBoperation generated errors. Check each OLE DB status value, if available. Nowork was done."How do I pick the returning id value and could anyone see were I'm goingwrong below.Many thanks for any help you can offer.CREATE PROCEDURE [sp_insert_address]@ADDR_NAME_2 [char](70),@ADDR_NO_3 [char](10),@ADDR_ROAD_4 [char](50),@ADDR_DISTRICT_5 [char](50),@ADDR_TOWN_6 [char](50),@ADDR_BOROUGH_7 [char](50),@ADDR_PCODE_8 [char](12),@addr_id [int] OUTPUTAS INSERT INTO [HEAPADLive].[dbo].[TBL_ADDR]([ADDR_NAME],[ADDR_NO],[ADDR_ROAD],[ADDR_DISTRICT],[ADDR_TOWN],[ADDR_BOROUGH],[ADDR_PCODE])VALUES(@ADDR_NAME_2,@ADDR_NO_3,@ADDR_ROAD_4,@ADDR_DISTRICT_5,@ADDR_TOWN_6,@ADDR_BOROUGH_7,@ADDR_PCODE_8)set @addr_id = scope_identity()GO

View 10 Replies View Related

Using Return Value From A Store Procedure ?

May 9, 2008

Dear all,

I have a store procedure called ValidateUser which retrtive an authneticated ID from a database.
This procedure is defined as follow :




Code Snippet
ALTER PROCEDURE [dbo].[ValidateUser]
-- Add the parameters for the stored procedure here
@LoginId int = 0 OUTPUT,
@UserName varchar(50),
@pw varchar(60),
@LineId varchar(16)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- return the User id as validted
SELECT @loginID = Id
FROM [NomosConfig].[dbo].Users
WHERE [UserName] = @UserName
AND [PassWord] = @pw
AND [LineId] = @LineId
-- if no record returns, the request user is not allowed
if @@ROWCOUNT < 1
SELECT @loginID = 0

END




Runing this procesdure alone work well and return correct LoginId


What I would like to do is retrieve that return LoginID inside an other procedure. For that I am doinmg as follow :




Code Snippet
DECLARE @AuthenticatedUserId int;



-- verify that user is authorized to access to PSU login
EXECUTE @AuthenticatedUserId= [ValidateUser]
@UserName ='cal'
,@pw ='cal'
,@LineId='PR495250'
SELECT @AuthenticatedUserId




What is strange is that the @AuthenticatedUserId is always retunring 0 ..
Did I write something wrong ?

thnaks fro help
serge

View 3 Replies View Related

Can Store Procedure Return Rows?

Feb 28, 2006

Can store procedure return rows?
If store procedure can return rows, how to use ASP.NET to receive it? thanks!

View 2 Replies View Related

Handle Store Procedure Return 2 Table

Sep 20, 2006

I have a sp that will do two select from two table. now, can datareader read both table or only dataset can? if datareader can? how to handle it?

View 1 Replies View Related

How To Get Store Procedure's Return Value And Output Parameters From BLL?

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

How To Code ASP.NET Page With Return Value Store Procedure?

Apr 12, 2005

Does anyone know how to call a SQL store procedure that return a value to the page?
I've a simple data entry aspx page with several textboxes and a save button. When user fill out the form and click save/submit, it calls a store procedure to insert a row into a SQL table and automatically generate an ID that need to return the the page to display for the user.
Are there a similar article somewhere?
 
Thank you all!

View 6 Replies View Related

Dataset Store Procedure Return Values

Apr 1, 2008



Hi All,
I have written a stored procedure that has a return value (OUTPUT Parameter) and was wondering if there is any way to retreive this value in SQL Server Reporting Services 2005? I get the result fine, but cannot figure out how to get the return parameter.

Thanks in advance.

Glenn

View 5 Replies View Related

Store Procedure Does Not Return All Rows Sometimes, Slow Execution...!!!

Oct 14, 2007

Dear friends,I have a problem with a simple select statement and I don't know why it is happening.I have 2 tables, Fees and FeesDataRoles. Fees presents all the fees and FeesDataRole is a middle table between Fees and Roles table. So each fee can have multiple Roles and a Role can have many Fees.Now I have a select statement:Select    *From     Fees Inner Join FeesDataRoles ON Fees.FeeID = FeesDataRoles.FeeIDWhere  (FeesDataRoles.DataRoleID = @DataRoleID) AND (FeesDataRoles.RecordStatus = 1 ) AND (FeesDataRoles.ValidFrom >= getdate() ) AND ( FeesDataRoles.ValidTo <= getdate() OR FeesDataRoles.ValidTo is null)Now it shouldn't take that long to execute this procedure but surprisingly sometimes when I insert a value to the table and then execute this store procedure it does now show the data just added. Very strange.....!!!!I ran the procedure 5 times after inserting an item and nearly 1 out of 5 does not return the right result righ. ( It does not include the recently inserted rows)Anyone have any idea....?I used Tuning Advisor, no sugestion. I change the clustered index in FeesDataRoles from FeesDataRoleID(the primary key of the table) to DataRoleID to increase the performance, still it happens sometimes.Is my Where clause so costly that cause this problem.Please help. I really appreciate your help.Regards,Mehdi 

View 2 Replies View Related

I Can Return INT From A Store Procedure But Get Error When OUTPUT A Varchar

Mar 21, 2008

My store procedure get the QuestionID (PK) from the page and then it's to return a few varchars but gives me the error that string can't be converted to int. ALTER PROCEDURE [dbo].[usp_getQuestionsforEditPopulateText]@QuestionID int,@QuestionDescription varchar(MAX) OUTPUT,@Option1 varchar(50) OUTPUT,@Option2 varchar(50) OUTPUT,@Option3 varchar(50) OUTPUT,@Option4 varchar(50) OUTPUT,@Option5 varchar(50) OUTPUT,@reference varchar(50) OUTPUT,@chb1 int OUTPUT,@chb2 int OUTPUT,@chb3 int OUTPUT,@chb4 int OUTPUT,@chb5 int OUTPUTAsSet @QuestionDescription =(Select questionDescription from QuestionsBank Where questionID = @QuestionID)Set @Option1 =(Select optionDescription from options Where questionID = @QuestionID and optionNumber = 1)Set @Option2 =(Select optionDescription from options Where questionID = @QuestionID and optionNumber = 2)Set @Option3 =(Select optionDescription from options Where questionID = @QuestionID and optionNumber = 3)Set @Option4 =(Select optionDescription from options Where questionID = @QuestionID and optionNumber = 4)Set @Option5 =(Select optionDescription from options Where questionID = @QuestionID and optionNumber = 5)Set @reference = (Select referencedescription from reference where questionID = @QuestionID)Set @chb1 = (Select correctOption from options where questionID = @QuestionID and optionNumber = 1)Set @chb2 = (Select correctOption from options where questionID = @QuestionID and optionNumber = 2)Set @chb3 = (Select correctOption from options where questionID = @QuestionID and optionNumber = 3)Set @chb4 = (Select correctOption from options where questionID = @QuestionID and optionNumber = 4)Set @chb5 = (Select correctOption from options where questionID = @QuestionID and optionNumber = 5) RETURN This is what the page callsDim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection("myconnectionstring ")        Dim cmdUpdate As New Data.SqlClient.SqlCommand("usp_getQuestionsforEditPopulateText", dbConnection)        cmdUpdate.CommandType = Data.CommandType.StoredProcedure        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@QuestionID", Data.SqlDbType.Int))        cmdUpdate.Parameters("@QuestionID").Value = QuestionID               cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@QuestionDescription", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@QuestionDescription").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@Option1", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@Option1").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@Option2", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@Option2").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@Option3", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@Option3").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@Option4", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@Option4").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@Option5", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@Option5").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@reference", Data.SqlDbType.VarChar))        cmdUpdate.Parameters("@reference").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@chb1", Data.SqlDbType.Int))        cmdUpdate.Parameters("@chb1").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@chb2", Data.SqlDbType.Int))        cmdUpdate.Parameters("@chb2").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@chb3", Data.SqlDbType.Int))        cmdUpdate.Parameters("@chb3").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@chb4", Data.SqlDbType.Int))        cmdUpdate.Parameters("@chb4").Direction = Data.ParameterDirection.Output        cmdUpdate.Parameters.Add(New Data.SqlClient.SqlParameter("@chb5", Data.SqlDbType.Int))        cmdUpdate.Parameters("@chb5").Direction = Data.ParameterDirection.Output        'open connection        dbConnection.Open()        'Execute non query        cmdUpdate.ExecuteNonQuery()        'close connection        dbConnection.Close() 

View 8 Replies View Related

Transact SQL :: Why Store Procedure Not Return Any Value / Result After Using Exec

Jul 22, 2015

I use new query to execute my store procedure but didnt return any value is that any error for my sql statement??

USE [Pharmacy_posicnet]
GO
/****** Object: StoredProcedure [dbo].[usp_sysconf] Script Date: 22/07/2015 4:01:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[usp_sysconf]

[Code] ....

View 6 Replies View Related

How To Return A String From A Stored Procedure

Mar 29, 2004

Up till now I've used SP's for updates and only ever needed to return error messages.

Now I have an SP that checks and validates something and has to return a string containing the result, (always a string/varchar!)

It works fine in Query Analyzer, I just need a demo of how to incorporate it into a VB app.

Hope that makes sense.

Thanks
Mark

View 4 Replies View Related

How Return String Value From Stored Procedure

Apr 3, 2008

This procedure gives a error : " Msg 245, Level 16, State 1, Procedure YAMAN, Line 16
Conversion failed when converting the nvarchar value 'user' to data type int. "
How can i return string value

ALTER procedure [dbo].[YAMAN]
(@username varchar(20),@active varchar(20))
as
begin
if exists (select username from aspnet_Users where username=@username)
begin
if @active=(select active from aspnet_Users where username=@username)
return 'already exist'
else
begin
update aspnet_Users set active=@active where username=@username
return 'update'
end
end
else
return 'user does not exist'
end

Yaman

View 2 Replies View Related

I Want To Return A String To A Wrapper From A Subordinate Stored Procedure

Sep 27, 2007

Using SQL Server 2000...I wrote a wrapper to call a sub proc (code provided below). Theintended varchar value returned in the output parameter of each procis a string implementation of an array.(The string separates elements by adding a period after each value.e.g. 1. 2. 3. 4. 5. etc., although my simplified example only createstwo elements.)My vb.net calling code parses the returned string into individualelements.I TESTED BOTH PROCS FIRST:The wrapper returns 'hello' when I test it by insertingSELECT @lString='hello'before the GO, so I believe it is called properly.The sub_proc returns the "array" I want when I call it directly.THE PROBLEM: When I call the wrapper, and expect it to call sub_proc,it returns a zero.In fact, when I assign a literal (like 'hello') to @lString insub_proc, 'hello' is not returned.So the wrapper is not calling the sub_proc, or the sub_proc is notreturning an output value.OR...I have read about some issues with OUTPUT string parameters beingtruncated or damaged somehow when passed. I doubt this is theproblem, but I'm open to anything.I want to use the wrapper because, when it's finally working, it willcall several sub_procs andreturn several output values.Any thoughts? Thanks for looking at it! - BobThe Wrapper:-----------------------------------------------------------------CREATE PROCEDURE wrapper@lString varchar(255) OUTASEXEC @lString = sub_proc @CommCode, @lString OUTGO-----------------------------------------------------------------The subordinate procedure:-----------------------------------------------------------------CREATE PROCEDURE sub_proc@lString varchar(255) OUTASDECLARE @var1 int,@var2 intSELECT @var1 =(SELECT count(mycolumn)FROM mytableWHERE condition=1)SELECT @var2 =(SELECT count(mycolumn)FROM mytableWHERE condition=2)/* If @var1 returns 5 and @var2 returns 7, Then @lString below wouldbe "5. 7." */SELECT @lString = STR(@var1) + '.' + STR(@var7) + '.'GO-----------------------------------------------------------------

View 3 Replies View Related

Transact SQL :: Search And Return String After Searched String

Sep 1, 2015

Is there way to search for the particular string and return the string after that searched string

SalesID
Rejection reason
21812

[code]....

The timeout period elapsed hence disqualified

View 3 Replies View Related

Find In String And Return Part Of String

Mar 21, 2007

I am trying to find a way to find a certian character in a string and then select everything after that character.

for example i would look for the position of the underscore and then need to return everthing after it so in this case

yes_no

i would return no

View 7 Replies View Related

Return Error Code (return Value) From A Stored Procedure Using A Sql Task

Feb 12, 2008


I have a package that I have been attempting to return a error code after the stored procedure executes, otherwise the package works great.

I call the stored procedure from a Execute SQL Task (execute Marketing_extract_history_load_test ?, ? OUTPUT)
The sql task rowset is set to NONE. It is a OLEB connection.

I have two parameters mapped:

tablename input varchar 0 (this variable is set earlier in a foreach loop) ADO.
returnvalue output long 1

I set the breakpoint and see the values change, but I have a OnFailure conditon set if it returns a failure. The failure is ignored and the package completes. No quite what I wanted.

The first part of the sp is below and I set the value @i and return.


CREATE procedure [dbo].[Marketing_extract_history_load_TEST]

@table_name varchar(200),

@i int output

as

Why is it not capturing and setting the error and execute my OnFailure code? I have tried setting one of my parameter mappings to returnvalue with no success.

View 2 Replies View Related

Store Procedures Return

Apr 28, 2000

Hi guys, I want to know if it is possible to retrieve the fieldnames that a
Stored Procedure return, without executing this StoreProc.

Thank you

View 1 Replies View Related

Return The New Id From A Store Proceedure

Mar 12, 2007

i have a store procedure which i need to get the returned id from how do i do this??

the sp:
CREATE PROCEDURE createpost(
@userID integer,
@categoryID integer,
@title varchar(100),
@newsdate datetime,
@story varchar(250),
@wordcount int
)
as

Insert Into TB_News(UserID, CategoryID, title, newsdate, StoryText, wordcount)
Values (@userID, @categoryID, @title, @newsdate, @story, @wordcount)

im calling it from asp, maybe i need to do something here as well im a bit lost really.. any help be great!

the asp:
con = new SqlConnection ("server=declt; uid=c1400046; pwd=c1400046; database=c1400046");
con.Open();

cmdselect = new SqlCommand("createpost", con);
cmdselect.CommandType = CommandType.StoredProcedure;



cmdselect.Parameters.Add("@userID", userID);
cmdselect.Parameters.Add("@categoryID", categoryID );
cmdselect.Parameters.Add("@title", title.Text );
cmdselect.Parameters.Add("@newsdate", newsdate.Text );
cmdselect.Parameters.Add("@story", story.Text );
cmdselect.Parameters.Add("@wordcount", "1" );


int userinserted = cmdselect.ExecuteNonQuery();


Response.Redirect("http://declt/websites/c1400046/newpicture.aspx?id=1");

View 1 Replies View Related

Store Return Result From Sp_columns

Oct 31, 2007

I excute sp_columns in my Stored Procedure script to get the data type of a table column.
EXEC sp_columns @table_name = 'XXX', @column_name='YYY'
How do i store the column 'TYPE_NAME' in the return row into a variable so that i can use it later in my stored procedure?
Thanks
Hannah

View 1 Replies View Related

Call Store Procedure From Another Store Procedure

Nov 13, 2006

I know I can call store procedure from store procedure but i want to take the value that the store procedure returned and to use it:

I want to create a table and to insert the result of the store procedure to it.

This is the code: Pay attention to the underlined sentence!

ALTER PROCEDURE [dbo].[test]



AS

BEGIN

SET NOCOUNT ON;



DROP TABLE tbl1

CREATE TABLE tbl1 (first_name int ,last_name nvarchar(10) )

INSERT INTO tbl1 (first_name,last_name)

VALUES (exec total_cash '8/12/2006 12:00:00 AM' '8/12/2006 12:00:00 AM' 'gilad' ,'cohen')

END

PLEASE HELP!!!! and God will repay you in kind!

Thanks!

View 7 Replies View Related

How To Store Different Languges String In Db?

May 8, 2008

Hi,
How to store different languges(unicode characters) string in db?

Swati

View 1 Replies View Related

Variable To Store String For Where Clause

Mar 26, 2001

I want to declare a variable that will serve as my where clause. The variable will be passed in from our website. Does anyone have any information or can guide me in the right direction to do this?

example:

@variable varchar(1000)

SELECT *
FROM table
WHERE @variable

(The @variable would reflect the where clause string)


Thanks!

View 1 Replies View Related

Store Connection String In Variable

May 10, 2007

Hi,



Does anyone know a way to store the ConnectionString of an OLEDB connection in a variable? I want to see exactly what values are in there because the step is failing with an error at that point. Here is what I'm looking for:



Data Source=;Initial Catalog=;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;





Thanks,

Phil

View 5 Replies View Related

Return Dat In String

Jul 25, 2007

hi! how would i return the current day in string format?

the output should be sun,mon,tue,wed,thu.. etc?

pls. help.. thanks

View 3 Replies View Related

Return Into One String

May 5, 2006

I have a table with a column called AccessTypes which contains a singleletter.I want to return these accesstypes from a query into one string. e.g.if there were 3 entries of A, S and DI want to select them and instead of returning 3 rows, I want just 1string like "ASD"can it be done?

View 3 Replies View Related

Transact SQL :: Split A String And Store As First And Second Part

Jul 17, 2015

I am using SQL Server 2008. I have strings like this:

AB-123
CDW-32
declare @First_Part varchar(3)
declare @Second_Part varchar(5)

I want to split the string with delimiter '-' and store as first part and second part.

I saw few sample functions to split a string but these return table of values.

I simply want first part and second part.

In above examples context:

@First_Part = 'AB'
@Second_Part = '123'

Any simple way to do this?

View 6 Replies View Related

Transact SQL :: Return Set Of Values From SELECT As One Of Return Values From Stored Procedure

Aug 19, 2015

I have a stored procedure that selects the unique Name of an item from one table. 

SELECT DISTINCT ChainName from Chains

For each ChainName, there exists 0 or more StoreNames in the Stores. I want to return the result of this select as the second field in each row of the result set.

SELECT DISTINCT StoreName FROM Stores WHERE Stores.ChainName = ChainName

Each row of the result set returned by the stored procedure would contain:

ChainName, Array of StoreNames (or comma separated strings or whatever)

How can I code a stored procedure to do this?

View 17 Replies View Related

Sqldatasource Return Into A String

May 28, 2007

Hi..
how can i insert the sqldatasource return into a string
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>" SelectCommand="SELECT COUNT(productID) FROM CSK_Store_Product"></asp:SqlDataSource>
this consults return a number of elements in the table, i need insert this number into a string
Thanks...

View 2 Replies View Related

Return Part Of A String

Mar 21, 2007

how can you return part of a string and convert it into an integer value? Maybe like this:

convert(left(column, 3) as int)

does that work?

The Yak Village Idiot

View 2 Replies View Related

'String Or Binary Data Would Be Truncated' - Trying To Store URLs

Mar 15, 2007

I am an absolute beginner with SQL Server 2005 Express, and I want to make a new table in my database that stores web URLs and their Username and Password info. When I try to add a URL to the URL column, it says

Error Source: .Net SqlClient Data Provider

Error Message: String or binary data would be truncated.

The statement has been terminated.

I assume this means that the URL is too long to fit in the data type I specified, but I've tried almost every single data type there is, and I keep getting the same error. I was wondering if anyone knew what was wrong.

Thanks for any help.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved