Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

error in Micorsoft 70-432 book Expand / Collapse
Author
Message
Posted Thursday, May 16, 2013 3:38 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 12:17 AM
Points: 238, Visits: 941
I am doing some practice exercises from Microsofts training kit for 70-432 Implementation and Maintenance 2008(written by Mike Hotek) and am running the following code from page 148 (chapter 6 distributing and partitioning data) - i am however getting an error. The error is shown below. I am running this from sql2012 developer management studio.

use partitiontest

SET NOCOUNT ON
DECLARE @month int,
@day int

SET @month = 1
set @day = 1

while @month <= 12
BEGIN
WHILE @day <=28
begin
INSERT dbo.orders (OrderDate, OrderAmount)
SELECT cast(@month as varchar(2)) + '/' + cast(@day as varchar(2))
+ '/2005', @day = 20

SET @DAY = @DAY +1
END
set @day = 1
set @month = @month + 1
end
go


The error i get is:
Msg 141, Level 15, State 1, Line 0
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
Msg 199, Level 15, State 1, Line 0
An INSERT statement cannot contain a SELECT statement that assigns values to a variable.

Is this because i am using sql2012 instead of 2008 ? I find it hard to imagine that what appears to be a basic error (for somebody who has written a book !) would be allowed to be published !!
Post #1453801
Posted Thursday, May 16, 2013 3:43 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Yesterday @ 8:42 AM
Points: 179, Visits: 819
PearlJammer1 (5/16/2013)
I am doing some practice exercises from Microsofts training kit for 70-432 Implementation and Maintenance 2008(written by Mike Hotek) and am running the following code from page 148 (chapter 6 distributing and partitioning data) - i am however getting an error. The error is shown below. I am running this from sql2012 developer management studio.

use partitiontest

SET NOCOUNT ON
DECLARE @month int,
@day int

SET @month = 1
set @day = 1

while @month <= 12
BEGIN
WHILE @day <=28
begin
INSERT dbo.orders (OrderDate, OrderAmount)
SELECT cast(@month as varchar(2)) + '/' + cast(@day as varchar(2))
+ '/2005', @day = 20

SET @DAY = @DAY +1
END
set @day = 1
set @month = @month + 1
end
go


The error i get is:
Msg 141, Level 15, State 1, Line 0
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
Msg 199, Level 15, State 1, Line 0
An INSERT statement cannot contain a SELECT statement that assigns values to a variable.

Is this because i am using sql2012 instead of 2008 ? I find it hard to imagine that what appears to be a basic error (for somebody who has written a book !) would be allowed to be published !!


Trust the error message - It's pointing you in the correct direction - Try SELECT cast(@month as varchar(2)) + '/' + cast(@day as varchar(2)) + '/2005', @day for the insert statement. You are trying to assign a value in the select stmt to the variable @day


SQL DBA
Every day is a school day, and don't trust anyone who tells you any different.
http://sqlblogness.blogspot.co.uk
Post #1453803
Posted Thursday, May 16, 2013 3:50 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 5:09 PM
Points: 23,089, Visits: 31,635
PearlJammer1 (5/16/2013)
I am doing some practice exercises from Microsofts training kit for 70-432 Implementation and Maintenance 2008(written by Mike Hotek) and am running the following code from page 148 (chapter 6 distributing and partitioning data) - i am however getting an error. The error is shown below. I am running this from sql2012 developer management studio.

use partitiontest

SET NOCOUNT ON
DECLARE @month int,
@day int

SET @month = 1
set @day = 1

while @month <= 12
BEGIN
WHILE @day <=28
begin
INSERT dbo.orders (OrderDate, OrderAmount)
SELECT cast(@month as varchar(2)) + '/' + cast(@day as varchar(2))
+ '/2005', @day = 20

SET @DAY = @DAY +1
END
set @day = 1
set @month = @month + 1
end
go


The error i get is:
Msg 141, Level 15, State 1, Line 0
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
Msg 199, Level 15, State 1, Line 0
An INSERT statement cannot contain a SELECT statement that assigns values to a variable.

Is this because i am using sql2012 instead of 2008 ? I find it hard to imagine that what appears to be a basic error (for somebody who has written a book !) would be allowed to be published !!


Typesetting errors occur. The original manuscript may have the above code just fine. Could just be a QA error before publishing.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1453804
Posted Thursday, May 16, 2013 4:33 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 12:17 AM
Points: 238, Visits: 941
Thanks - you where correct. I ommite the = 20 and it worked.
Thank you very much
Post #1453808
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse