How to use select statement in a delete statement using MSSQL

To use select statement in a delete statement using MSSQL you can use the snippet below.

Sample MSSQL

DELETE TableOne
FROM   TableOne
       INNER JOIN TableTwo
               ON TableTwo.Id= TableOne.Id
                  AND ...
                       WHERE ...

Please rate this snippet

How to use a select in update statement using MSSQL

To use a select statement in a update statement using MSSQL you can use the snippet below.

Sample SQL

UPDATE TableOne
SET
    t1.ColumnOne = t2.ColumnOne,
    t1.ColumnTwo = t2.ColumnTwo
FROM
    TableOne AS t1
INNER JOIN
    TableTwo AS t2
ON
    TableOne.id = TableTwo.id

Please rate this snippet

How to get the Month name of a Datetime in C# and VB.NET

To get the Month name of a Datetime in C# and VB.NET you can use the following snippet.

Sample C#

Console.WriteLine(new DateTime(2010, 1, 1).ToString("MMM", CultureInfo.InvariantCulture)); //Jan
Console.WriteLine(new DateTime(2010, 1, 1).ToString("MMMM", CultureInfo.InvariantCulture)); //January

Sample VB.NET

Console.WriteLine(New DateTime(2010, 1, 1).ToString("MMM", CultureInfo.InvariantCulture))
'Jan
Console.WriteLine(New DateTime(2010, 1, 1).ToString("MMMM", CultureInfo.InvariantCulture))
'January

Please rate this snippet

How to query a DataTable using LINQ in C# and VB.NET

To query a DataTable using LINQ in C# and VB.NET you can use the snippet below.
In order to use the snippet, you need to reference System.Data.DataSetExtensions.

Sample C#

var resultData = (from myDataRow in myDataTable.AsEnumerable() where myDataRow.Field<Int32>("Fieldname") == 1 select myRow);

Sample VB.NET

Dim resultData = (From myDataRow In myDataTable.AsEnumerable() Where myDataRow.Field(Of Int32)("Fieldname") = 1myRow)

Please rate this snippet

How to get monday date of current week in MSSQL

To get the Monday date of the current week you can use the snippet below.

SELECT DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) AS Monday

Please rate this snippet

How to get all column names of a Table in Oracle

To get all column names of a Table in Oracle you can use the following snippet.

SELECT table_name, column_name, data_type, data_length
FROM USER_TAB_COLUMNS
WHERE table_name = 'TABLENAME'

If you are using MSSQL, take a look at this snippet -> How to list all columns from a table in MSSQL

Please rate this snippet

How to get a list of all tables in Oracle

To get a list of all tables in Oracle you can use the following query.

SELECT owner, table_name FROM dba_tables

if your user does not have sufficient access rights to query dba_tables, you can try to query all_tables which will only show you the tables you are allowed to see.

SELECT owner, table_name FROM all_tables

Please rate this snippet

How to use IF ELSE in an SQL Select query

In MSSQL IF ELSE is not supported inside the SQL-Query.
For a similiar behaviour you should use CASE WHEN keyword.

Sample Query

SELECT CASE 
            WHEN [Productnumber] LIKE '112%' THEN 'SOFTWARE'
			WHEN [Productnumber] LIKE '005%' THEN 'HARDWARE'
		    ELSE 'MISC' 
       END as [ProductType] 
FROM dbo.[Products]

Please rate this snippet