Home > Ask the SQL Server Experts > Greg Low - Development Questions & Answers > Syntax error in SQL Server script
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

Syntax error in SQL Server script

Greg Low EXPERT RESPONSE FROM: Greg Low

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 13 February 2007
I'm currently working on table partitioning. I'm struggling with using this " SELECT MAX(NAME) from sys.filegroups WHERE NAME NOT LIKE 'PRIMARY' " in order to get the last used Filegroup. Now this works just fine, but when I run the following script: --Decalre variables DECLARE @LastFilegroupName VARCHAR(50) DECLARE @FilegroupName VARCHAR(50) --Retuns the next FileGroup to be used SET @LastFilegroupName = (select MAX(NAME) from sys.filegroups WHERE NAME NOT LIKE 'PRIMARY') SET @LastFilegroupName = Replace(@LastFilegroupName,'FileGrp','') SET @FilegroupName = 'FileGrp' + CAST((@LastFilegroupName + 1) as varchar(10)) --Alter database statement ALTER DATABASE VadivelTesting ADD FILEGROUP @NewFG_Name This script gives the following error "Incorrect syntax near '@NewFG_Name'." When I give it a static name it works fine, but not with the variable. What should I do?


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Greg Low - Development
Copy stored procedure between SQL Server 2005 databases
Should developers have permissions to SQL Server production queue?
Schedule stored procedure and save output to network drive
Query to find SQL Server database names created by users
Is it possible to find disabled indexes in SQL Server 2000?
SQL Server id permission to create and modify tables
Problem attaching stored procedure and SQL Server trigger
Installing different SQL Server versions on one machine
Calling an extended stored procedure in SQL Server 2005
Multiple SQL Server instances vs. multiple databases

SQL Server Development
Change tempdb from 'C' drive
Tempdb changes in SQL Server 2005
Sub-queries supported in Analysis Services MDX
MDX functions: SCOPE, THIS and FREEZE
More powerful Analysis Services MDX in SQL Server 2005
CASE statements now supported by MDX script
Top 5 SQL Server query tips
Update table rows in SQL Server 2000
Delete .bak files automatically with CLR
Stored procedure overview in SQL Server
SQL Server Development Research

Microsoft SQL Server
Avoid cursors in SQL Server with these methods to loop over records
Implementing security audit in SQL Server 2008
What's new in SQL Server 2008 Reporting Services?
SQL Server replication methods: Snapshot, merge or transactional
New security features in SQL Server 2008 leave some work for you
How to disable the shrink database task in SQL Server 2000 and 2005
New datetime data types in SQL Server 2008 offer flexibility
SQL Server out of memory: Troubleshoot and avoid SQL memory problems
SQL Server errors, failures and other problems fixed from the trenches
SQL Server consolidation: Why it's an optimization technique

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



SQL Solutions - SQL Database Design
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts