SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Go keyword
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chbala85
Starting Member

49 Posts

Posted - 06/19/2013 :  01:50:47  Show Profile  Reply with Quote
Hi ,

DECLARE @CompanyNameTest AS VARCHAR(50)
Go

SET @CompanyNameTest = 'Exact help'

The above script giving error .....

please explain Go keyword ............


visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/19/2013 :  01:56:41  Show Profile  Reply with Quote
GO keyword is a batch separator. SO usage in above case cause the batch to end. When you use variable again after it it becomes out of scope as variable has scope only inside batch it was created. Thats why you get the error

it should be this


DECLARE @CompanyNameTest AS VARCHAR(50)

SET @CompanyNameTest = 'Exact help' 
... other code using @CompanyNameText

Go



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/19/2013 :  01:58:26  Show Profile  Reply with Quote
You can also redefine it if you want

http://visakhm.blogspot.com/2010/02/custom-batch-separator-in-t-sql.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000