Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Must declare scaler variable???

Author  Topic 

lawrence_brd
Starting Member

4 Posts

Posted - 2012-03-31 : 10:08:14
Hi there, I am trying to execute this script but it isnt working...
It keeps throwing out an error saying: Error: Must declare scaler variable @g


Does anybody know why?

Any help would be greatly appreciated! :)

DECLARE @g AS geography;
SET @g = geography::STGeomFromText('LINESTRING(-122.364 47.656, -122.345 47.656)', 4326) ;
GO;

INSERT INTO [Address] (addr_line1, addr_line2, addr_line3, addr_cityTown, addr_stateCounty, addr_country_id#, addr_notes, addr_image, addr_long, addr_lat, addr_postCode) VALUES
-- Business Sites
('Unit 2B', 'Sedgefield Way', NULL, 'Sedgefield', 'West Yorkshire', 27, 'Company owned property', NULL, @g , @g1, 'YO43 5TR'),

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-31 : 10:37:17
Because the GO breaks the batch, and variables are only in scope in the batch they are defined it.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

lawrence_brd
Starting Member

4 Posts

Posted - 2012-03-31 : 11:21:52
Thanks :) I removed the GO statement but still no joy
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-03-31 : 13:17:24
You need to declare and assign value to the variable @g1 too

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

lawrence_brd
Starting Member

4 Posts

Posted - 2012-03-31 : 14:46:54
I know I have already done that but only incuded the first @g declaration
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-31 : 16:55:15
Post the code. If we can't see it, we can't tell you what's wrong

Make sure there's not a second GO in there.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-31 : 19:28:40
quote:
Originally posted by lawrence_brd

I know I have already done that but only incuded the first @g declaration


the posted code doesnt have @g1 declared anyways.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lawrence_brd
Starting Member

4 Posts

Posted - 2012-04-05 : 14:53:03
USE [K0078208_Removals]
GO

-- Create a longitude and latitude geography data type to use as sample data


DECLARE @g AS geography;
DECLARE @g1 AS geography;
DECLARE @g2 AS geography;
DECLARE @g3 AS geography;

SET @g = geography::STGeomFromText('LINESTRING(-122.364 47.656, -122.345 47.656)', 4326) ;
SET @g1 = geography::STGeomFromText('LINESTRING(-122.320 47.656, -122.313 47.656)', 4326);
SET @g2 = geography::STGeomFromText('LINESTRING(-122.264 47.656, -122.245 47.656)', 4326);
SET @g3 = geography::STGeomFromText('LINESTRING(-122.390 47.656, -122.313 47.556)', 4326);


INSERT INTO [Address] (addr_line1, addr_line2, addr_line3, addr_cityTown, addr_stateCounty, addr_country_id#, addr_notes, addr_image, addr_long, addr_lat, addr_postCode) VALUES
-- Business Sites
('Unit 2B', 'Sedgefield Way', NULL, 'Sedgefield', 'West Yorkshire', 27, 'Company owned property', NULL, @g , @g1, 'YO43 5TR'),
('Unit FL', 'Larpool Ind. Estate', 'Larpool Road', 'Whitby', 'North Yorkshire', 27, 'Company owned property', NULL, NULL, NULL, 'YO21 1BZ'),
('49', 'Repelton Ind. Estate', NULL, 'Birmingham', 'West Midlands', 27, 'Company owned property', NULL, NULL, NULL, 'WM23, 5QA'),
('Bishopton Depot', 'Bishopton Ind. Estate', NULL, 'Billingham', 'Cleveland', 27, 'Company owned property', NULL, NULL, NULL, 'TS19, 4AA'),
('37B/F', 'Crofton Business Park', 'Crofton Road', 'Edinbrugh', 'Edinbrugh', 27, 'Company owned property', NULL, NULL, NULL, 'SC24 5QQ'),
('12', 'Jessops Way', NULL, 'Aberyswyth', 'Aberyswyth', 27, 'Company owned property', NULL, NULL, NULL, 'WA11 7BH'),
('19, Lakeview Ind. Estate, Lakeview High Pass', 'Ipswich', 'Suffolk', 27, 'Company owned property', NULL, NULL, NULL, 'SF12 5RK'),
('13F', 'North Skelton', NULL, 'Guisbrough', 'Cleveland', 27, 'Company owned property', NULL, @g2, @g3, 'TS4 9BZ')
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-04-05 : 17:14:17
First thing I noticed there is that the row constructors don't have the same number of columns for each row.

This line has only 9 columns, the rest have 11 - ('19, Lakeview Ind. Estate, Lakeview High Pass', 'Ipswich', 'Suffolk', 27, 'Company owned property', NULL, NULL, NULL, 'SF12 5RK')

Other than that, the code ran fine for me.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -