how to create query sqlserver in store procedure for display data random - sql-server-2005

how to create query sqlserver in store procedure for display data random
select * from View_lap where codex in ('020573.007','280680.041','020277.006')
this code put in store procedure
CREATE PROCEDURE displdata
#ncodex ntext -
AS
BEGIN
select * from View_lap where codex in (#ncodex )
but i found error

Related

Storing results of a stored procedure in a Google Big Query table

Here is a link to the question I asked earlier. The accepted answer works perfectly.
But this stored procedure processes 2 statements and after running this procedure I have to click on View Results of the second statement to see the result in Google Big Query. Is there a way to save the results in some table automatically using the 'Query Settings' in Google Big Query and specifying the name of the table I want to store the results in?
You cannot set a destination table for a script (or for call a procedure), instead, you can convert your SELECT statement into CREATE TABLE ... AS SELECT, for example:
SELECT 1 x;
=>
CREATE TABLE myDataset.myTable
AS SELECT 1 x;
You can define a string parameter for your procedure. Then use this parameter in the dynamic query to write the results to the table.
CREATE OR REPLACE PROCEDURE `my_dataset.my_procedure`(destination_table STRING)
BEGIN
CREATE TEMP TABLE tmp AS SELECT 1 x;
EXECUTE IMMEDIATE (
FORMAT("CREATE OR REPLACE TABLE `%s` AS SELECT * FROM tmp", destination_table));
END
Now you can provide a table name and call this procedure to write the results to the table.
CALL `my_dataset.my_procedure`("my_dataset.my_table");
SELECT * FROM `my_dataset.my_table`

Convert Query to Stored Procedure

In db2, can someone show me how to convert a query into a stored procedure, so that when the stored procedure is called it simply returns the same result set as the query would return.
For example, let say I have query like this:
select * from tablename
How would you turn this into a stored procedure that returns the same record set as is returned by just simply running the query directly?
Just create a procedure
Format is as follows
CREATE PROCEDURE <<SPmyProcedure>>
AS
BEGIN
<---procedure definition here--->
select * from tablename
END
Then you can just call the procedure name and it will perform your query.
via
exec SPmyProcedure
Why you dont use table valued function like this?
ALTER FUNCTION [db].[fn_tablename]
(
)
RETURNS TABLE
AS
RETURN
(
SELECT * from [db].tablename
)

SAP HANA: Loading tables from with statements in stored procedures

Is it possible to load a table from a with statement via a stored procedure in HANA? Nothing i try seems to work, and the only thing that does work when creating a procedure is just displaying the data from the with statement via a select. Below I show three examples I have tried for accessing with statement data. Currently on HANA revision 84. Please note the table create is just for purposes of the test example.
CREATE PROCEDURE test_proc
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
create table t1 (cal_day date);
with w1 as (
select current_date cal_day from dummy
)
--works just fine but isn't loading the data into anything
select * from w1;
--get indentifier must be declared error
select cal_day into t1 from w1;
--get incorrect syntax error
insert into t1
select cay_day from w1;
END
When you want to execute DDL statements in a SQLScript procedure you'll need to use dynamic SQL for that (EXEC).

select top 0 * INTO #temp from stored procedure

select top 0 * INTO #temp from stored procedure
Need to create temp table based on the structure of data type returned from stored procedure.
Using sql server 2000,2005, 0r 2008
You can't do this. To get the results from a stored procedure, you have to first define the structure of the results:
create table #temp ( . . . );
insert into #temp
exec(stored procedure)
If you examine the syntax for the SELECT statement (here), you'll see no reference to running a stored procedure.
Perhaps you should post another question describing what you are trying to do. Why would a stored procedure be returning different result formats?

SQL Server - Pass image to stored procedure, invalid local var type

I have two tables that contain document content: one for temporary staging, other for permanent storage. The content is stored as type image (cannot change this since it's current functionality).
I need a stored procedure that does the following:
Pass in a TempDocumentID that exists in temp document table.
With that TempDocumentID, select image content from temp document table.
Exec existing stored procedure that takes an image parameter to insert into permanent document table.
My problem is two-fold:
I can't declare a local variable of type 'image' to fill from the select statement of temp table. It throws error 'The text, ntext, and image data types are invalid for local variables.'
I don't know of a way to exec stored proc with direct results from select statement of temp table.
Here is my SQL Fiddle example: http://sqlfiddle.com/#!3/09384/5
Thanks,
Greg
Try this, it doesn't get an error in SQL Fiddle. I believe it will pass the result from the sub-query:
CREATE PROCEDURE MoveDocumentFromTemp
(
#TempDocumentID numeric(18,0)
)
AS
BEGIN
EXEC InsertDocumentContentFinal (SELECT TempContent
FROM DocumentContentTemp (NOLOCK)
WHERE TempDocumentID = #TempDocumentID)
END
You should be able to use VARBINARY(MAX) with SQL Server 2005 and later.
CREATE PROCEDURE MoveDocumentFromTemp
(
#TempDocumentID numeric(18,0)
)
AS
BEGIN
DECLARE #ContentToMove varbinary(max)
SELECT #ContentToMove = cast(TempContent as varbinary(max))
FROM DocumentContentTemp (NOLOCK)
WHERE TempDocumentID = #TempDocumentID
EXEC InsertDocumentContentFinal #ContentToMove
END
GO
For SQL Server 2000, you'll just have to include the INSERT code from MoveDocumentFromTemp directly into your wrapper stored procedure.