Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Below queries in sql giving weird results. Please help me to understand why it is happening.
exec sp_executesql N'SP_MNP_DownLoadFiles #FileTypeId,#UserId',N'#FileTypeId smallint,#UserId bigint',#FileTypeId=2,#UserId=18 -- This query returns nothing
Exec SP_MNP_DownLoadFiles #FileTypeId=2,#UserId=18 -- This query returns some result
Select Type as FileTypeId ,FileStream as Attachment FROM MNPFiles
where CustomerId = 18
AND
Type = 2 -- This is the query inside SP.
Please consider the data types are same everywhere.
What I am doing wrong here?
Your dynamic SQL string doesn't match your non-dynamic statement.
exec sp_executesql N'EXEC SP_MNP_DownLoadFiles ...',...
^^^^
Other things to check:
Other SELECTs in your stored procedure prior to your main one. You may need to SET NOCOUNT ON.
That you're not RETURNing something before your main query
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We need to add a parameterised select in a pl/sql function. But I don't know what is a parameterised select. :(
You are probably talking about using bind variables in SQL statement in a PL/SQL code, like this:
declare
anumb number:=1;
.....
begin
select ....
into ....
from your_table
where a_column=anumb .....;
....
end;
In this sample code, the select can be called 'parameterised', as is uses a variable set before in the SQL. 'anumb' can also be a parameter passed to a function or procedure.
Finally, why do you tag your quest with sql-server when you have PL/SQL in the subject?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a stored procedure where I like to display each Name in the table below
on a separate line with a PRINT so the user can see what has been retreived:
Select Name from Persons;
What is the best way to do this as I can use a cursor and then through each iteration display the Name with the PRINT. Is there a better way to do this?
I think the best way would be to select the output you want to show the user at the end of the procedure:
CREATE PROC dbo.test
AS
BEGIN
--do stuff
INSERT INTO foo (bar)
SELECT name
FROM persons
--select what to show user
SELECT name
FROM persons
END
PRINT doesn't work inside a stored procedure.
If you run the code without being wrapped in a SP, it will display what you want.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I've to help migrating a SQL Server 2008 database to a PostgreSQL 9.4.10 one. The original querys have SET NOCOUNT ON and SET NOCOUNT OFF several times, and I can't change this fact so ignoring the number of rows affected isn't a solution. That's why I need to find an equivalent to this statement, but all I can find are really old posts where they say I should ignore the result. Any ideas? Thanks.
EDIT: these SET NOCOUNTare inside a stored procedure that goes like this:
CREATE PROCEDURE [procedureName]
Declares
--Variables
WITH ENCRYPTION
AS
SET NOCOUNT ON
--Procedure's code
SET NOCOUNT OFF
GO
As I've said this code isn't mine, so I can't post any of it more than the source of my doubt.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
HI I want to take a passed parameters of a stored procedure, and then use that to update or add rows to a table. is that possible?
Here's a basic example of how to do it.
-- Create the stored procedure
CREATE PROCEDURE usp_TestSp
#Param1 INT
AS
INSERT INTO Table1 VALUES (#Param1)
GO
-- Execute the stored procedure
EXEC dbo.usp_TestSp #Param1 = 2 -- int
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have read this post about USING clause in EXECUTE IMMEDIATE statements:
Then I just wanted to test it for non-null values:
declare mydate date;
begin
mydate := to_date('01.01.2001','dd.mm.yyyy');
execute immediate 'insert into test_testik(DATEZ)
values :x' using mydate;
end;
The result is following error
03001. 00000 - "unimplemented feature"
*Cause: This feature is not implemented.
Any ideas why does this happen?
Thank you in advance!
You should surround :x with parentheses according to Oracle syntax.