SELECT field1,
field2,
field3,
fieldname = CASE [field4]
WHEN '9' THEN 'Semi Trailer'
WHEN '7' THEN 'Pole Trailer'
WHEN '6' THEN 'Other'
WHEN '5' THEN 'Motor Carrier'
WHEN '3' THEN 'Full Trailer'
WHEN '2' THEN 'Dolly Converter'
WHEN '14' THEN 'Intermodal Chassis'
WHEN '12' THEN 'Van'
WHEN '11' THEN 'Truck Tractor'
WHEN '10' THEN 'Straight Truck'
ELSE 'Invalid'
END
FROM [dbo].[kansiris].
Showing posts with label SQL server. Show all posts
Showing posts with label SQL server. Show all posts
Difference between CTE and Temp Table and Table Variable

Temp Table or Table variable or CTE are commonly used for storing data temporarily in SQL Server. In this article, you will learn the differences among these three.CTECTE stands for Common Table expressions. It was introduced with SQL Server 2005. It is a temporary result set and typically it may be a result of complex sub-query. Unlike temporary table its life is limited to the current query. It is defined by using WITH statement. CTE.
Calculate Running Total, Total of a Column and Row

Many times, you required to show information of each transaction and also keep a Running Total and Final Total like GridView in Asp.Net. In this article, I am going to explain, how can you achieve this using SQL Query in simple and easy way.Suppose you have the below CustomerOrders table and has the data as shown below:CREATE TABLE CustomerOrders( OrderID int identity, Amount Decimal(8,2), OrderDate SmallDatetime default getdate() ) Go.