stored-procedures

mysql count rows with a specific column

烂漫一生 提交于 2020-04-07 04:20:30
问题 I have a table like this Sr Name 1 A 2 B 3 C 4 C 5 C 6 E 7 A 8 A 9 A 10 E 11 B 12 B I need output like this A = 4 Times B = 3 Times C = 3 Times E = 2 Times How can I achieve this? Thanks in advance 回答1: SELECT Name, COUNT(Sr) FROM myTable GROUP BY Name ORDER BY Name ASC; 回答2: You may want to use: SELECT name, CONCAT(COUNT(*), ' Times') number FROM your_table GROUP BY name ORDER BY name; Test case: CREATE TABLE your_table (sr int, name varchar(50)); INSERT INTO your_table VALUES(1, 'A');

What happens if altering a stored procedure while it is running?

只谈情不闲聊 提交于 2020-04-05 08:45:12
问题 I have a minor, one line change (fixing a typo in a string), to a stored procedure that I would like to deploy to our production SQL Server 2005 server as soon as possible. The worry I have is what happens if at the exact time run the alter statement to update my stored procedure, it happens that something calls that stored procedure at the same time? Does it run with the previous copy of the stored procedure, or can it result to some corruption or errors? Considering the ACID nature of SQL

Compare two tables and insert all records with added or removed status in another table using SQL Server procedure [duplicate]

徘徊边缘 提交于 2020-03-28 06:48:28
问题 This question already has answers here : Compare two tables and insert all records with added or removed status in 3rd table using SQL Server procedure (5 answers) Closed last month . 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 description A desc A B desc B C desc C D desc D E desc E F desc F G desc G H desc H I desc I J desc J table B name description A desc A B desc B M desc M N desc N

Getting a returned value/parameter from MySQL using aspx.cs

别说谁变了你拦得住时间么 提交于 2020-03-26 03:29:23
问题 I have a simple procedure in MySQL (same as in Retrieving values of function output/proc output parameters in JavaScript from ADODB commands to MySQL?). As an attempt to get around the dead end of not being able to fetch the values of the output parameters, I started working on this from the aspx.cs component of a C# VisualStudio website project. However, this method so far doesn't even execute the procedure, let alone return the values. //MySQL Procedure - where user readonly has read and

Create a stored procedure to insert a new data in a table

人盡茶涼 提交于 2020-03-19 05:58:39
问题 I want to create a stored procedure to insert a new row in a table 'dbo.Terms' CREATE PROCEDURE dbo.terms @Term_en NVARCHAR(50) = NULL , @Createdate DATETIME = NULL , @Writer NVARCHAR(50) = NULL , @Term_Subdomain NVARCHAR(50) = NULL AS BEGIN SET NOCOUNT ON INSERT INTO dbo.terms ( Term_en , Createdate , Writer , Term_Subdomain ) VALUES ( @Term_en = 'Cat' , @Createdate = '2013-12-12' , @Writer = 'Fadi' , @Term_Subdomain = 'English' ) END GO But is shows me an Error here ( @Term_en = 'Cat')

Invalid column name exception when calling an Oracle stored procedure with ref_cursor through JPA 2.1

可紊 提交于 2020-03-18 09:09:54
问题 I am trying to execute an Oracle stored procedure using JPA. I am able to retrieve results if I build the query and call the stored procedure through the query.getResultList() as shown below: @Autowired EntityManager em; public List<MyEntity> callStoredProcedure(String paramOneValue, String paramTwoValue) { StoredProcedureQuery query = em.createStoredProcedureQuery("storedProcedureName"); query.registerStoredProcedureParameter("paramOneName", String.class, ParameterMode.IN); query

Invalid column name exception when calling an Oracle stored procedure with ref_cursor through JPA 2.1

本小妞迷上赌 提交于 2020-03-18 09:07:35
问题 I am trying to execute an Oracle stored procedure using JPA. I am able to retrieve results if I build the query and call the stored procedure through the query.getResultList() as shown below: @Autowired EntityManager em; public List<MyEntity> callStoredProcedure(String paramOneValue, String paramTwoValue) { StoredProcedureQuery query = em.createStoredProcedureQuery("storedProcedureName"); query.registerStoredProcedureParameter("paramOneName", String.class, ParameterMode.IN); query

How to create a database using SQL stored procedure?

徘徊边缘 提交于 2020-03-16 08:35:47
问题 How to create a database using SQL stored procedure? Why can not I send the database as a variable? Is there a restriction on sending the database name from the outside? How can I do this if there is such a restriction? create proc AddDatabase @Name varchar(100), @FileName varchar(Max), @Size int, @Maxsize int, @FileGrowth int, @logName varchar(100), @LogFileName varchar(Max), @LogSize int, @LogMaxsize int, @LogFileGrowth int) as begin Create database @Name On Primary (NAME=@Name FileName=

SqlNullValueException when executing a stored procedure with MySqlCommand

妖精的绣舞 提交于 2020-03-16 06:53:28
问题 I'm writing a C# application to retrieve recipes from a MySQL database, using Dapper for ORM. So far, I've written my DAL in C# with direct queries (Which I know is unsafe), and this works great. I've now started to transition over to stored procedures with parameters to better protect the database from SQL injection, as well as just using as close to best practice as I can. However, when I'm using Dapper's QueryAsync<T> (This also applies to Query<T> ) along with DynamicParameters , I get an

Passing Multiple Between Statements To Stored Procedure

廉价感情. 提交于 2020-03-16 06:26:54
问题 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