Archive for the ‘sql’ Category

case in sql(a nice sql query)

This is a nice sql query, I was afraid with a table and finally i got WITH CASE which helped me to implement confition in query. nice……..

SELECT CASE WHEN price IS NULL THEN ‘Not yet priced’ WHEN price = 10 and price THEN ‘Very Reasonable Title’ WHEN price >= 10 and price <= 20 THEN ‘Coffee Table Title’ ELSE ‘Expensive book!’ END AS “Price Category”, CONVERT(varchar(20), title) AS “Shortened Title” FROM pubs.dbo.titles ORDER BY price

Read Full Post »

important in query

Some time we want not to get null values returning from our query and to protect this need to use ISNULL. hrre is an example fo using ISNULL.
ISNULL((SELECT name FROM employee WHERE id = employeeSalary.eID), ”)
Name of the employee id returnig from this query but if name is null it return a space.
Sometime we need to cast a field here is an example of casting value
(SELECT RTrim(CAST(day AS char(3))) + ‘-‘ + RTrim(CAST(month AS char(3))) + ‘-‘ + RTrim(CAST(year AS char(3))) FROM employee AS date
it cast and concate day month and year

Read Full Post »