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
 Go keyword

Author  Topic 

chbala85
Starting Member

49 Posts

Posted - 2013-06-19 : 01:50:47
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

52326 Posts

Posted - 2013-06-19 : 01:56:41
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

52326 Posts

Posted - 2013-06-19 : 01:58:26
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
   

- Advertisement -