1: | What function enables you to provide a value for nulls? |
A1: | The function you would use to determine whether a column is NULL and then replace it with a value is the ISNULL() function. |
2: | What is the result of this query?Use Pubs Select 'My name is '+ au_fname From authors Where au_id = '172-32-1176' |
A2: | The first name of the author with this au_id would be appended to the string, "My name is ". The output would beMy name is Johnson |
3: | What column name is displayed by this query?Use Pubs Select au_fname as 'First Name' From authors |
A3: | Answer: The column name that would be displayed isFirst Name |
4: | What would be the result of the following query?Use Pubs Select 'My price is '+ price From titlesWhere title like '%Computer%' |
A4: | This was really a trick question. The query will produce an error message only because the price column data type is Money and you are asking to concatenate it with a string constant. The error message isServer: Msg 260, Level 16, State 1, Line 2 Disallowed implicit conversion from data type varchar to data type money, table 'pubs.dbo.titles', column 'price'. Use the CONVERT function to run this query. |
1: | When was the first employee hired by Northwind? |
A1: | The first employee who was hired will have the lowest or minimum date in the hiredate column of the employees table:Select min(hiredate) From Employees Results: ------------------------------------------------------ 1992-04-01 00:00:00.000 (1 row(s) affected) |
2: | What is today's date and what day of the week is it? |
A2: | You would use the GETDATE() function to retrieve today's date. Then, to get the day of the week, you could use either the DATEPART() or DATENAME() functions. The SELECT statement you would use is as follows:Select getdate(), datepart(dw, getdate()), datename(dw, getdate()) Results: --------------------------- ----------- ------ 2000-10-08 13:11:09.723 1 Sunday (1 row(s) affected) |
3: | How many hours until New Year's Day? |
A3: | The answer to this question is calculated by asking for the DATEDIFF() between now and 1/1/2002. To specify hours in the function by using the hh DATEPART() code:select datediff(hh,getdate(), '1/1/2002') |