Tag: sql-server

54 votes
17 answers
1K views
Entity Framework: There is already an open DataReader associated with this Command

I am using Entity Framework and occasionally i will get this error. EntityCommandExecutionException {"There

avatar
Suzan
0 1 0 9
asked 07 September, 2021
61 votes
16 answers
2.1K views
DateTime2 vs DateTime in SQL Server

Which one: datetime datetime2 is the recommended way to store date and time in SQL Server 2008+? I'm a

avatar
Hallie
0 1 0 9
asked 07 September, 2021
57 votes
22 answers
2.5K views
How can I get column names from a table in SQL Server?

I want to query the name of all columns of a table. I found how to do this in: Oracle MySQL PostgreSQL But I a

avatar
Emilia
0 1 0 9
asked 07 September, 2021
55 votes
27 answers
2.1K views
How can I list all foreign keys referencing a given table in SQL Server?

I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the foreign

avatar
Thurman
0 1 0 9
asked 07 September, 2021
51 votes
11 answers
2.8K views
How to Join to first row

I'll use a concrete, but hypothetical, example. Each Order normally has only one line item: Orders: Or

avatar
Gigi
0 1 0 9
asked 07 September, 2021
56 votes
14 answers
2.5K views
Should I use != or <> for not equal in T-SQL?

I have seen SQL that uses both != and <> for not equal. What is the preferred syntax and why? I like !=

avatar
Lorenzo
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
963 views
Exclude a column using SELECT * [except columnA] FROM tableA?

We all know that to select all columns from a table, we can use SELECT * FROM tableA Is there a way to excl

avatar
Patsy
0 1 0 9
asked 07 September, 2021
55 votes
21 answers
1.8K views
Function vs. Stored Procedure in SQL Server

I've been learning Functions and Stored Procedure for quite a while but I don't know why and when I

avatar
Keila
0 1 0 9
asked 07 September, 2021
63 votes
24 answers
2.6K views
Search text in stored procedure in SQL Server

I want to search a text from all my database stored procedures. I use the below SQL: SELECT DISTINCT o.

avatar
Scot
0 1 0 9
asked 07 September, 2021
63 votes
15 answers
1.4K views
When should I use CROSS APPLY over INNER JOIN?

What is the main purpose of using CROSS APPLY? I have read (vaguely, through posts on the Internet) that cros

avatar
Sena
0 1 0 9
asked 07 September, 2021
61 votes
25 answers
3K views
SQL update from one Table to another based on a ID match

I have a database with account numbers and card numbers. I match these to a file to update any card numbers to

avatar
Boyd
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
2.5K views
Parameterize an SQL IN clause

How do I parameterize a query containing an IN clause with a variable number of arguments, like this one? SEL

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
57 votes
14 answers
985 views
How do I escape a single quote in SQL Server?

I am trying to insert some text data into a table in SQL Server 9. The text includes a single quote '. Ho

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
57 votes
6 answers
2.6K views
Difference between JOIN and INNER JOIN

Both these joins will give me the same results: SELECT * FROM table JOIN otherTable ON table.ID = otherTable.

avatar
Scot
0 1 0 9
asked 07 September, 2021
60 votes
14 answers
3.1K views
SQL Server - Best way to get identity of inserted row?

What is the best way to get IDENTITY of inserted row? I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDE

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
63 votes
16 answers
2.6K views
How can I do an UPDATE statement with JOIN in SQL Server?

I need to update this table in SQL Server with data from its 'parent' table, see below: Table: sale

avatar
Freida
0 1 0 9
asked 07 September, 2021
63 votes
15 answers
381 views
How can I delete using INNER JOIN with SQL Server?

I want to delete using INNER JOIN in SQL Server 2008. But I get this error: Msg 156, Level 15, State 1, L

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
1.9K views
How do I perform an IF...THEN in an SQL SELECT?

How do I perform an IF...THEN in an SQL SELECT statement? For example: SELECT IF(Obsolete = 'N' OR

avatar
Joseph
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.3K views
Insert results of a stored procedure into a temporary table

How do I do a SELECT * INTO [temp table] FROM [stored procedure]? Not FROM [Table] and without defining [temp

avatar
Chelsea
0 1 0 9
asked 07 September, 2021