Tag: tsql

52 votes
14 answers
870 views
How to do SQL Like % in Linq?

I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organi

avatar
Venice
0 1 0 9
asked 07 September, 2021
54 votes
6 answers
1.8K views
Linq to Sql: Multiple left outer joins

I'm having some trouble figuring out how to use more than one left outer join using LINQ to SQL. I under

avatar
Frederick
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
964 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
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
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
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
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
60 votes
30 answers
2.9K views
How to return only the Date from a SQL Server DateTime datatype

SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 0

avatar
Corrin
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.7K views
How do I UPDATE from a SELECT in SQL Server?

In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement: INSERT INTO Table

avatar
Jefferey
0 1 0 9
asked 07 September, 2021