tagged [sql]

The variable name '@' has already been declared. Variable names must be unique within a query batch or stored procedure

The variable name '@' has already been declared. Variable names must be unique within a query batch or stored procedure > The variable name '@LockState' has already been declared. Variable names must ...

18 Jan at 16:57

Is there an Entity Framework 7 Database-First POCO Generator?

Is there an Entity Framework 7 Database-First POCO Generator? I've been playing around with Entity Framework 7 and ASP.NET 5 for a new project I'm working on, but I've hit a roadblock. The team I'm wo...

updating table rows in postgres using subquery

updating table rows in postgres using subquery I have this table in a postgres 8.4 database: I want to update the table. Initially i tested my q

10 Jan at 00:29

Function vs. Stored Procedure in SQL Server

Function vs. Stored Procedure in SQL Server When should I use a function rather than a stored procedure in SQL, and vice versa? What is the purpose of each?

Retrieving the date in SQL Server; CURRENT_TIMESTAMP vs GetDate()

Retrieving the date in SQL Server; CURRENT_TIMESTAMP vs GetDate() Using SQL Server, which is the fastest or best practice method to use for date retrieval? Is there a difference between `CURRENT_TIMES...

6 Jan at 15:22

How to log PostgreSQL queries?

How to log PostgreSQL queries? How to enable logging of all SQL executed by PostgreSQL 8.3? I changed these lines : And restart PostgreSQL service... but no log was created... I'm using Windows Server...

6 Jan at 13:9

How to skip certain database tables with mysqldump?

How to skip certain database tables with mysqldump? Is there a way to restrict certain tables from the mysqldump command? For example, I'd use the following syntax to dump `table1` and `table2`: But i...

3 Jan at 20:50

Check if a row exists, otherwise insert

Check if a row exists, otherwise insert I need to write a T-SQL stored procedure that updates a row in a table. If the row doesn't exist, insert it. All this steps wrapped by a transaction. This is fo...

29 Dec at 01:2

Reset auto increment counter in postgres

Reset auto increment counter in postgres I would like to force the auto increment field of a table to some value, I tried with this: AND I have a table `product` with `Id` and `name` field

29 Dec at 00:48

SQL Query slow in .NET application but instantaneous in SQL Server Management Studio

SQL Query slow in .NET application but instantaneous in SQL Server Management Studio Here is the SQL ``` SELECT tal.TrustAccountValue FROM TrustAccountLog AS tal INNER JOIN TrustAccount ta ON ta.Trust...

27 Dec at 23:24

Save byte[] into a SQL Server database from C#

Save byte[] into a SQL Server database from C# How can I save a byte[] array into a SQL Server database? This byte[] contains a HashAlgorithm value. The data is needed again for later use. So converti...

27 Dec at 01:52

Why would reusing a DataContext have a negative performance impact?

Why would reusing a DataContext have a negative performance impact? After a [fair](https://learn.microsoft.com/en-us/archive/blogs/dsimmons/context-lifetimes-dispose-or-reuse) [amount](https://weblog....

MSSQL Select statement with incremental integer column... not from a table

MSSQL Select statement with incremental integer column... not from a table I need, if possible, a t-sql query that, returning the values from an arbitrary table, also returns a incremental integer col...

SQL: how to select a single id ("row") that meets multiple criteria from a single column

SQL: how to select a single id ("row") that meets multiple criteria from a single column I have a very narrow table: user_id, ancestry. The user_id column is self explanatory. The ancestry column cont...

22 Dec at 01:6

SQL Server 2008 - Help writing simple INSERT Trigger

SQL Server 2008 - Help writing simple INSERT Trigger This is with Microsoft SQL Server 2008. I've got 2 tables, Employee and EmployeeResult and I'm trying to write a simple INSERT trigger on EmployeeR...

22 Dec at 01:4

How to use If Statement in Where Clause in SQL?

How to use If Statement in Where Clause in SQL? I need to use if statement inside where clause in sql. ``` Select * from Customer WHERE (I.IsClose=@ISClose OR @ISClose is NULL) AND (C.FirstName lik...

How to use multiple conditions (With AND) in IIF expressions in ssrs

How to use multiple conditions (With AND) in IIF expressions in ssrs I want to hide rows in SSRS report having Zero Quantity. There are following multiple Quantity Columns like Opening Stock, Gross Di...

21 Dec at 21:36

Creating a custom query with Spring DATA JPA?

Creating a custom query with Spring DATA JPA? I'm working on a project with Spring Data JPA. I have a table in the database as my_query. I want to create a method which takes a string as a parameter, ...

Stored procedure with default parameters

Stored procedure with default parameters I am trying to create a stored procedure based on a query I wrote with parameters that are predefined. When restructuring to a create stored procedure and I ex...

How can I tell if a VARCHAR variable contains a substring?

How can I tell if a VARCHAR variable contains a substring? I thought it was `CONTAINS`, but that's not working for me. I'm looking to do this: I have to run one `select` or another, depending on wheth...

21 Dec at 04:50

Filter df when values matches part of a string in pyspark

Filter df when values matches part of a string in pyspark I have a large `pyspark.sql.dataframe.DataFrame` and I want to keep (so `filter`) all rows where the URL saved in the `location` column contai...

GROUP BY having MAX date

GROUP BY having MAX date I have problem when executing this code: Basically, I want to return the most recent date for each control number. The query above returns correct output but it takes 37secs. ...

MySQL Sum() multiple columns

MySQL Sum() multiple columns I have a table of student scorecard. here is the table, Now, I need to sum it for each student of total marks. I got it by using `sum(mark1+mark2+...+markn) group by

19 Dec at 19:52

Add column to SQL Server

Add column to SQL Server I need to add a column to my SQL Server table. Is it possible to do so without losing the data, I already have?

19 Dec at 09:45

Update one MySQL table with values from another

Update one MySQL table with values from another I'm trying to update one MySQL table based on information from another. My `original` table looks like: And the `tobeupdated` table looks like: ``` uniq...

18 Dec at 22:49