stored-procedures

MySQL procedure returns empty result to PHP

僤鯓⒐⒋嵵緔 提交于 2021-02-20 19:57:48
问题 I have an issue where I wrote a stored procedure that inserts data into a bunch of tables and then finally returns and id by selecting it. when I execute the stored procedure in PHPMyAdmin, the data is inserted and the ID returned. When executing the procedure from PHP using MySQLi, the data is inserted into the tables however when I check the results to retrieve the new id, the result seems to be blank. Any help here would be appreciated. I am not sure if the procedure returns empty results

SQL BCP with column name

天涯浪子 提交于 2021-02-20 04:44:07
问题 I am trying to export my stored procedure to a .csv file using BCP. It does give me a output file in .CSV but it does not print column name. Below is the script. Please look at and let me know what i am missing DECLARE @command VARCHAR(4000) declare @fulldate varchar(30) = convert(varchar,GETDATE(),112) declare @year varchar(30) = left(@fulldate,4) declare @day varchar(30) = right(@fulldate,2) declare @month varchar(30) = left(right(@fulldate,4),2) DECLARE @FileDirectory VARCHAR(1000) = 'c:\'

Allow login to run stored procedure without being able to select from table

非 Y 不嫁゛ 提交于 2021-02-19 05:33:44
问题 I have a SQL Server with two databases: Database1 Database2 Login 'MyLogin' has read access on Database2 only. Database2 has a stored procedure as follows: CREATE PROCEDURE Get_LogData @ProductID int AS BEGIN If Exists (Select (1) From Database2.dbo.Products Where ProductID = @ProductID) Select LogTimeStamp , ProductID , Description from Database1.dbo.Log Where ProductID = @ProductID Else Print 'Get_LogData: Unable to find ProductID ' + CAST(@ProductID AS VARCHAR) END; GO BEGIN GRANT EXEC ON

Writing stored procedures when using dynamic schema names in sql server

醉酒当歌 提交于 2021-02-19 04:15:34
问题 The application, I have been currently working with has different schema names for its tables, for example Table1 can have multiple existence say A.Table1 and B.Table1. All my stored procedures are stored under dbo. I'm writing the below stored procedures using dynamic SQL. I'm currently using SQL Server 2008 R2 and soon it will be migrated to SQL Server 2012. create procedure dbo.usp_GetDataFromTable1 @schemaname varchar(100), @userid bigint as begin declare @sql nvarchar(4000) set @sql=

Writing stored procedures when using dynamic schema names in sql server

 ̄綄美尐妖づ 提交于 2021-02-19 04:15:30
问题 The application, I have been currently working with has different schema names for its tables, for example Table1 can have multiple existence say A.Table1 and B.Table1. All my stored procedures are stored under dbo. I'm writing the below stored procedures using dynamic SQL. I'm currently using SQL Server 2008 R2 and soon it will be migrated to SQL Server 2012. create procedure dbo.usp_GetDataFromTable1 @schemaname varchar(100), @userid bigint as begin declare @sql nvarchar(4000) set @sql=

Writing stored procedures when using dynamic schema names in sql server

余生颓废 提交于 2021-02-19 04:14:03
问题 The application, I have been currently working with has different schema names for its tables, for example Table1 can have multiple existence say A.Table1 and B.Table1. All my stored procedures are stored under dbo. I'm writing the below stored procedures using dynamic SQL. I'm currently using SQL Server 2008 R2 and soon it will be migrated to SQL Server 2012. create procedure dbo.usp_GetDataFromTable1 @schemaname varchar(100), @userid bigint as begin declare @sql nvarchar(4000) set @sql=

How to pass byte[] from C# as string to SQL Server stored procedure and convert into varbinary(MAX)

笑着哭i 提交于 2021-02-18 17:55:47
问题 In this project, there is a class which wraps ADO.NET for common data access like ExecuteDataReader , ExecuteScalar , etc.. When using these methods to call a stored procedure, it allows you to pass a Dictionary<string, string> of parameters (string key, string value), which are then added to the SqlCommand object as SqlParameter . There is a case where we have to save a document in the database. The document is a byte[] and the corresponding column in the database is varbinary(MAX) . We've

Customise default 'New Stored Procedure' SSMS 2008 Template

£可爱£侵袭症+ 提交于 2021-02-17 14:46:47
问题 I am trying to customise the default query which is put in place when you click New Stored Procedure... from the Object Explorer on SQL Server Management Studio 2008. I have found how to change the 'Create Stored Procedure (New Menu)' template from the Template Explorer , however this means I will have to keep opening the template explorer rather than clicking on new stored procedure like i usually would. How can I edit the template which appears when you click New Stored Procedure... ? 回答1:

Create a stored procedure in SQL Server that returns total count of columns in table and distinct count of values in each column

我只是一个虾纸丫 提交于 2021-02-17 07:24:16
问题 I need a stored procedure that takes any table name as a parameter and returns total count of rows and distinct count of values in each column of that particular table when executed. Let's take the sample table as below: create table journey ( Src varchar(255), Dest varchar(255) ) insert into journey values ('Jaipur', 'Mumbai'), ('Mumbai', 'Jaipur'), ('Kolkata', 'Bangalore'), ('Bangalore', 'Indore'),('Indore', 'Lucknow'), ('Lucknow', 'Indore') Can anybody help me with this task of dynamic SQL

Stored Procedure with multi value parameter behaving strangely

穿精又带淫゛_ 提交于 2021-02-17 05:10:12
问题 I created a stored procedure in sql server to feed SSRS to allow it to accept Multiple values. I have created it and when I used it in my report or execute it in sql server I have the following error message. Is there anything i am missing? Thanks Msg 207, Level 16, State 1, Line 35 Invalid column name 'London'. This is my sample data. feel free to create table with it DECLARE @MyTables AS TABLE (ID INT, City VARCHAR(100)) INSERT INTO @MyTables VALUES (1,'London'), (2,'Chester'), (3,'Luton'),