stored-procedures

Saving data in a SQL Server 2016 database for a specfic report

烈酒焚心 提交于 2020-02-07 03:50:06
问题 I was not sure how to title this but let me explain. I need to pull all of the publication article ID's from PubMed for every member of a Cancer Center. The ID's are normally 6 or 7 digest long. Currently I'm using a Stored Proc to save the id's in a comma separated string with the email address is the unique ID for the member. INSERT INTO [dbo].[ADMIN_Publications] ([Organization], [email], [PMID]) VALUES (@Organization, @Email, @PMID, ) The PMID's could be like 23579449,25465297,26512957

Stored Procedure Null Error

眉间皱痕 提交于 2020-02-06 19:04:50
问题 I am learning Mysql stored procedure and I am getting error Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1 delimiter // drop procedure if exists getUserData// create procedure getUserData( in firstName varchar(50), in lastName varchar(50), in gender varchar(50), in email varchar(50), in userType varchar(50), in isActive int, in isDeleted int, in createdBy date, in dob date

Stored Procedure Null Error

别来无恙 提交于 2020-02-06 19:04:08
问题 I am learning Mysql stored procedure and I am getting error Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1 delimiter // drop procedure if exists getUserData// create procedure getUserData( in firstName varchar(50), in lastName varchar(50), in gender varchar(50), in email varchar(50), in userType varchar(50), in isActive int, in isDeleted int, in createdBy date, in dob date

How to grant user access to a DB from inside a stored procedure in SQL Server- Getting Error: USE database statement is not allowed in a procedure

点点圈 提交于 2020-02-06 08:03:26
问题 I need to grant the user access to a database from inside a stored procedure in SQL Server, but when I try to use this code, the DB in use does not change and when I run the code without using EXEC , I get an error: USE database statement is not allowed in a procedure My code: CREATE PROCEDURE [dbo].[usp_AddUserDBToTables] (@UserGroup NCHAR(30), -- DBdetail, DBxref @DBName NCHAR(30)) -- DBdetail, DBxref AS BEGIN DECLARE @sqlcmd NVARCHAR(1024); -- Add the UserGroup to the new UserDB SET

create a table with date name

戏子无情 提交于 2020-02-05 13:57:06
问题 I am writing a simple procedure to backup a table- CREATE PROCEDURE daily_backup() BEGIN DECLARE given_date VARCHAR(25); SET given_date = now(); CREATE TABLE given_date LIKE db1.table1; INSERT INTO given_date SELECT * FROM db1.table1; END But it creates a table with name given_date . I want to create a table with date as name. How to do the same ? 回答1: Try this one DELIMITER | CREATE PROCEDURE daily_backup() BEGIN SET @s = CONCAT('CREATE TABLE bak_', DATE_FORMAT(CURDATE(), '%Y%m%d'), ' SELECT

Regarding Execute Immediate in stored procedure

旧街凉风 提交于 2020-02-04 01:28:09
问题 I am having the below statement from stored procedure. It's giving Insufficient Privileges. But If i run the create statement alone from the sql prompt it's creating table. execute immediate 'create table TEST_ABC( NO_AC NUMBER(8) , ILL_PER VARCHAR2(15) , INIT_C DATE )'; What needs to be done to have priviliges to create table via execute immediate from stored procedure. Not sure how it's working from sql command prompt 回答1: Procedures don't inherit privileges granted via a role. More info

How do I get the Identity field that results from an insert?

别等时光非礼了梦想. 提交于 2020-02-03 08:43:29
问题 I'm going to insert data into a table like so: Insert Into MyTable (Field1, Field2) Values ('test', 5) When that insert occurs, the new row is going to have an identify value in the ID column. If have a variable called @ID in my T-SQL code, how do I populate @ID with the result of the T-SQL Insert? Declare @ID int Insert into MyTable (Field1, Field2) Values ('test', 5) --//How do I populate @ID with the value of ID of the record that was just inserted? 回答1: There are two ways - the first is

How do I get the Identity field that results from an insert?

我的梦境 提交于 2020-02-03 08:42:40
问题 I'm going to insert data into a table like so: Insert Into MyTable (Field1, Field2) Values ('test', 5) When that insert occurs, the new row is going to have an identify value in the ID column. If have a variable called @ID in my T-SQL code, how do I populate @ID with the result of the T-SQL Insert? Declare @ID int Insert into MyTable (Field1, Field2) Values ('test', 5) --//How do I populate @ID with the value of ID of the record that was just inserted? 回答1: There are two ways - the first is

Stored Procedure Maximum Pattern Match

风流意气都作罢 提交于 2020-02-03 08:25:47
问题 This is my stored procedure in Oracle: CREATE OR REPLACE PROCEDURE execute_cproc ( callnum IN VARCHAR2 , RESULT OUT VARCHAR2) AS vara_val NUMBER; varb_val NUMBER; BEGIN SELECT a_val, b_val INTO vara_val, varb_val FROM data_table WHERE callnum LIKE numberpattern || '%'; END; If CALLNUM is 03354123 then I am getting 2 results: 03354123 like 033% 03354123 like 03354% Both are true so I'm getting 2 results. How to make procedure find the longest matching only, i.e. 03354123 like 03354% ? Table :

Is a return value of 0 always a success in stored procedures?

*爱你&永不变心* 提交于 2020-02-03 03:16:12
问题 If a stored procedure returns a value of zero, does that always mean it was run successfully? I am using MS SQL Server 2008. 回答1: No, you can return something yourself example CREATE PROC pr_test AS SELECT 1/0 RETURN 0 GO Now run it DECLARE @i INT exec @i = pr_test SELECT @i -- will be 0 DROP PROC pr_test Now let's do it again without the return statement CREATE PROC pr_test2 AS SELECT 1/0 GO DECLARE @i INT exec @i = pr_test2 SELECT @i -- will be - 6 Better to use an output parameter to pass