stored-procedures

Passing Multiple Between Statements To Stored Procedure

不打扰是莪最后的温柔 提交于 2020-03-16 06:26:09
问题 I have a table full of products, previously we passed a MaxPrice and MinPrice to the stored procedure and selected products with the price between two values. But now I want to pass multiple range values and want to select products that their prices are between multiple ranges. Let's say I had a stored procedure like this: @PriceMin decimal(18, 4) = null, @PriceMax decimal(18, 4) = null, ... WHERE product.Price > @PriceMin AND product.Price < @PriceMax but now I want to pass multiple range of

Creating a query from XML input parameter in SQL Server stored procedure and verifying output

老子叫甜甜 提交于 2020-03-05 07:02:13
问题 I have created a stored procedure that reads XML data as its input. I am having two issues that I am hoping someone can help with. Issue 1: When I execute the stored procedure, I only get back the first value for AccountType (9). I am expecting/wanting to get back all values for AccountType . Issue 2: Once I have fixed the above issue I would like to use values from AccountType to select users from another table e.g. dbo.UserData What I have tried: I saw this on another SO post that you can

How to pass parameter value to a stored procedure rather than text lietral in SQL Server [duplicate]

坚强是说给别人听的谎言 提交于 2020-03-04 23:08:28
问题 This question already has answers here : SQL CREATE LOGON - can't use @parameter as username (4 answers) Closed 12 days ago . Taking the next step from the recent post (below) How to grant access to multiple schemas in one go in SQL Server I created this stored procedure: ALTER PROCEDURE dbo.CreateUser @loginName nvarchar(100), @userName nvarchar(100) , @schemaName nvarchar(10) AS SET NOCOUNT ON; IF NOT EXISTS (SELECT [name] FROM [sys].[database_principals] WHERE [TYPE] = N'S' AND [name] =

Postgres stored function input-checking overhead, interpreting timing results

你离开我真会死。 提交于 2020-03-03 08:26:52
问题 While answering another question, Klin demonstrated an easy way of doing some loose timing tests. The question is "How expensive are exceptions?" There are mentions in the documentation and elsewhere that PL/PgSQL is slower than SQL for stored functions, and that EXCEPTION is expensive. I have no intuition about Postgres' performance in these situations, and figured I'd try out a few comparisons. Klin showed how to use the (wonderful) generate_series() function to make this easy. And here's

Postgres stored function input-checking overhead, interpreting timing results

天涯浪子 提交于 2020-03-03 08:25:13
问题 While answering another question, Klin demonstrated an easy way of doing some loose timing tests. The question is "How expensive are exceptions?" There are mentions in the documentation and elsewhere that PL/PgSQL is slower than SQL for stored functions, and that EXCEPTION is expensive. I have no intuition about Postgres' performance in these situations, and figured I'd try out a few comparisons. Klin showed how to use the (wonderful) generate_series() function to make this easy. And here's

Python: Execute Stored Procedure with Parameters

我怕爱的太早我们不能终老 提交于 2020-03-02 07:27:31
问题 I'm working on a Python script that writes records from a stored procedure to a text file. I'm having issues executing the stored procedure with parameters. I'm not sure what I could do differently to execute this stored procedure with both parameters. You can see the error I'm getting below. Any insight would be appreciated. Here's my code # Import Python ODBC module import pyodbc # Create connection cnxn = pyodbc.connect(driver="{SQL Server}",server="<server>",database="<database>",uid="

Python: Execute Stored Procedure with Parameters

早过忘川 提交于 2020-03-02 07:26:28
问题 I'm working on a Python script that writes records from a stored procedure to a text file. I'm having issues executing the stored procedure with parameters. I'm not sure what I could do differently to execute this stored procedure with both parameters. You can see the error I'm getting below. Any insight would be appreciated. Here's my code # Import Python ODBC module import pyodbc # Create connection cnxn = pyodbc.connect(driver="{SQL Server}",server="<server>",database="<database>",uid="

Group by multiple columns on a single MySql stored procedure

感情迁移 提交于 2020-03-02 05:58:50
问题 I have the below stored procedure which I use to show data on multiple ASP chart items. CREATE DEFINER=`root`@`localhost` PROCEDURE `GetChartApprovedData`(in siteValue varchar(45), in skillValue varchar(100), in shiftValue varchar(100), in tmValue varchar(45), in grpmValue varchar(45), in dateValue date, in dateValue1 date) BEGIN SELECT count(agentlogin) AS totalApproved, shift AS Shift, skill AS Skill, tm AS TM, grpM AS GrpM FROM approved WHERE (sitevalue IS NULL OR site = sitevalue) AND

Compare two tables and insert all records with added or removed status in 3rd table using SQL Server procedure

爱⌒轻易说出口 提交于 2020-02-26 04:04:12
问题 I have table A and table B . I have to compare this tables records and insert data to table C using SQL Server procedure in below format table A name A B C D E F G table B name A B Q C D F G table c should be like below. it has an extra field 'status' to mention record is added or removed. name status A B Q newly added C D E removed F G I know we can compare 2 tables and find added or removed records using EXCEPT and UNION operations. But in this case, I have to integrate that records with

How To Call Postgres 11 Stored Procedure From Python

为君一笑 提交于 2020-02-24 07:01:07
问题 I have a Postgres Procedure called sales and work well in pgadmin with CALL sales(); However, I encounter error when called from python scripts... as below import psycopg2 conn = psycopg2.connect (host ....) cur = conn.cursor() cur.callproc('sales') conn.commit() Error message as below: psycopg2.ProgrammingError: sales() is a procedure LINE 1: SELECT * FROM sales() ^ HINT: To call a procedure, use CALL. 回答1: Assuming your procedure is called sales, you just need to "call" it e.g. CALL sales()