|
|
|
|
Browse by Tags
All Tags » Teaser (RSS)
Showing page 2 of 3 (30 total posts)
-
Print the @SQL variable without using PRINT
DECLARE @SQL varchar(49)
SELECT @SQL = 'Print This Now ' + CONVERT(VARCHAR(30), GETDATE())
--Your Code Here
-
Without running this code try to guess what the values of @var1 and @var2 will be
CREATE TABLE #TeasMeNot(id int)
DECLARE @var1 int,@var2 int
SELECT @var1=0,@var2 = 0
SELECT @var1 =id FROM #TeasMeNot
SELECT @var2 = (SELECT id FROM #TeasMeNot)
--What is the value of @var1 and @var2?
SELECT @var1,@var2
DROP TABLE #TeasMeNot
-
What will happen when you run this?
Create Table #Dots(Data VarChar(50))
Insert Into...#Dots Values('Huh?') --3 dots
Insert Into..#Dots Values('Huh, say what?') --2 dots
Select * From .#Dots -- 1 dot
Drop Table #Dots --look no dots!
-
What do you think will be the output? DECLARE @d datetime SET @d = '20071010' SELECT DATEADD(yy, DATEDIFF(yy, 0, @d)+1, -1)
-
Here is a small teaser, can you guess the output? SELECT d.c-d.b/d.a FROM(SELECT 1 c,2 b,5 a)d(a,b,c)
-
What will be the outcome of this script?First we create a table with a total of 6000 bytesNext we increase col2 from 1000 to 2000 bytes, this will give us a total of 7000 bytesFinally we add col3 which has 1000 bytes, this will give us a total of 8000 bytes
First run these two statements--Total size = 6000CREATE TABLE TestSize (Col1 ...
-
Hi and welcome to another fascinating SQL summer teaser.
Summer it is except in Princeton where it was 50 degrees this week.
There was no teaser last week because of a death in the family, I had to go to a wake and a funeral last week. That is why this teaser will be posted on a Thursday instead of a Friday this week ;-)
look at these values ...
-
The teaser for this week is not really a teaser, this time you will have to write some code instead of guessing/knowing.First create this table of numbers
SET NOCOUNT ON
CREATE TABLE numbers(num int primary key)
DECLARE @l int
SELECT @l =0
WHILE @l <= 1000
BEGIN
INSERT numbers VALUES(@l)
SET @l = @l + 1
END
GO
Below is a table, ...
-
Here is a fun teaser. NULLIF will return a null value if the two specified expressions are equivalent.So to give an exampleDECLARE @v varcharSET @v = ' ' SELECT NULLIF(@v,' ')That returned NULL because @v and ' ' are the sameNow run this firstCREATE TABLE #j (n varchar(15))DECLARE @a intSET @a = 1WHILE @a <= 1000 BEGININSERT #jSELECT ...
-
This one is not so much a teaser but it will show you what you can do in case you want to insert data in a logging table after a rollback occursWithout running this try to guess what the counts of the three tables will be after the rollbackCREATE TABLE Test (id int)CREATE TABLE #Test (id int)DECLARE @Test table (id int)BEGIN TRAN ...
2
|
|
|
|
|