And this will really exceed 8000 characters? When it is a variable, it is only 8000 characters; for executing a query that is longer than 4000 ANSI characters is therefore impossible to do from a variable, such as EXEC (@SQL). 6. xp_readmail for email longer than 8000 characters. You're in the best position to judge because its your data. (GO required before a second :CONNECT). This technique could prove to be useful in some cases and therefore it's good to know we have it as an option. [' + @Grouping + '].CURRENTMEMBER.MEMBER_CAPTION, FROM (SELECT {[Shop]. Becasue I can't give you the my original query. use you original query to create a view on the remote server (of course, if you can do it): SELECT * FROM RemoteReport in your OPENQUERY statement. Why did Ukraine abstain from the UNHRC vote on China? decided it would be faster to write one myself than search the broader the following example shows. In some applications, having hard coded SQL statements is not appealing because My query is 8621 chars long I broke the query into twoVARCHAR(8000) variables, one was 7900 and the other was 721. Try to use a ##temp (global) table instead of a #temp (local) table. Generally the length of a varchar (Max) data type consider it as a 8000 characters and above. SELECT {[Measures].[GroupingParam],[Measures].[Season],[Measures].[Value],[Measures].[COGS],[Measures].[Units],[Measures].[Delivered],[Measures].[CountryRank],[Measures].[CountryValue],[Measures].[CountryCOGS],[Measures].[CountryUnits]. I am using SQL Server 2008. sql sql-server sql-server-2008 Share Improve this question Follow :) :thumbsup: Permalink. PRINT is limited to 8000 characters, the actual variable may contain more characters. The query stored in the variable receives truncated once it reaches the limit. [All]', set @Stores='[Shop]. Do you have a chance to either create a view or a sproc at the db referenced in OPENQUERY that would hold the content of @sqlquery? If you have Unicode/nChar/nVarChar values you are concatenating, then SQL Server will implicitly convert your string to VarChar(8000), and it is unfortunately too dumb to realize it will truncate your string or even give you a Warning that data has been truncated for that matter! Thanks for contributing an answer to Stack Overflow! Even the while loop condition on shop parameter does not help us because we have to get Top N value for all the shops and in case of while loop it gives the Top N value of each shop. e.g. How would such a parameter string look like? [' + @Grouping + ']. Dynamic SQL is a programming technique you can use to build SQL statements as textual strings and execute them later. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. Example: . we are executing the same code shared with you. [Stores2 Sales Cost - Base], [Articles]. Make sure which is causing the error. I wisht to fetch out the total record count from the Table. For those who hit a 4000 character max, it was probably because you had Unicode so it was implicitly converted to nVarChar(4000). [' + @Grouping + ']. INSERT INTO #temp SELECT DISTINCT CONVERT (smalldatetime, AttendanceDate, 103) AS Pivot FROM dbo.vw_ARS_StudentClassAttendance WHERE RegisterID = @RegisterID . How can I output more than 256 characters to a file? I have tried everything I can think of to get around this limitation but I can not figure out a way around this. With the Execute Statement you are building the SQL statement on the fly and can pretty much do whatever you need to in order to construct the statement. The way to solve this is to make multiple variables or multiple rows in a table that you can iterate through. To learn more, see our tips on writing great answers. @Mani - the reason that the @city variable is declared twice is because it is used outsite of the sp_executesql and also within the sp_executesql. One issue is the potential for Maximum length is 8000.) [Brand].&[VANS].&[Outlet].&[0SS]', set @FiscalTime=N'[Time]. --The below code works fine hardcoding with a number like 6 to get the moving average(6), But I want to use the @myparam so I can reuse the same function to get moving average (3) or (12) ie. Asking for help, clarification, or responding to other answers. e.g. Is there a single-word adjective for "having exceptionally strong moral principles"? Thanks for your suggestion. Dynamic SQL commands using EXEC Statement. I will try to update this in the near future. I suggest you ask a new question rather than adding on to a 10-year old answered thread. Managing SQL Server string with more than 8000 characters First of all, this error appears if you tried to declare an argument of type TEXT in a stored procedure as follows: CREATE PROCEDURE MY_PROCEDURE @Variable_Text TEXT AS BEGIN DECLARE @VARIABLE_TEXT TEXT -- The problem is in this line [Shop Model],[Measures].[Stock],[Measures]. The contents of this blog/website are not intended to defame, purge or humiliate anyone should they decide to act upon or reuse any information provided by me. I have looked at kinds of examples on the internet..but gets confusing because most of the examples use a temp table. @StackNewUser: that will not help, since, @StackNewUser: Thanks you. I'm not getting the results I expected and cant tell what the problem is. setting up and using dynamic SQL functionality in your T-SQL code: looks like you cannot pass in a parameter that way for that clause. So basically, if you have 2008, both the text solution and the varchar(max) will work, so you will have time to change it =-). the fly. Making statements based on opinion; back them up with references or personal experience. Native Dynamic SQL is the easier way to write dynamic SQL. but my code below doeas not accept the parameter. Step 3 : How can I enter values to varchar(max) columns, dynamic sql passing parameter of length > 8000, Pad a string with leading zeros so it's 3 characters long in SQL Server 2008, Handling more than 8000 chars in stored proc parameter, why varchar(max) is not storing data more than 8000 charaters, SQL Server is not printing more than 8000 length of data. Is there a single-word adjective for "having exceptionally strong moral principles"? forward, because you also need to define the extra quotes in order to pass a character Linear regulator thermal information missing in datasheet. Thanks a lot. Has anyone found a better way to preserve formatting while printing a string more than 8,000 characters?perhaps through a custom function or procedure? Transact-SQL syntax conventions Syntax syntaxsql You can probably avoid truncation by defining all the variables involved as nvarchar(MAX). Hi Elkin, I tried this and it works in SSMS, but I had to change the fomula as follows: DECLARE @ValorFrm NVARCHAR(500) = 'SET @Valor_OUT=983.14-2*(15.5)+1', DECLARE @SqlString NVARCHAR(500)DECLARE @ParmDefinition NVARCHAR(500)DECLARE @Valor_Tmp Numeric(12,2)SET @SqlString=LTRIM(RTRIM(@ValorFrm))SET @ParmDefinition = N'@Valor_OUT Numeric(12,2) OUTPUT', EXECUTE sp_executesql @SqlString,@ParmDefinition,@[emailprotected]_Tmp OUTPUT, Lo que busco es el total de esa operacion compuesta. Viewed 2k times 1 I have a SQL script with more than 8000 characters and I stored it in some VARCHAR (MAX). take a look at this tip about how to create tables to see if this helps: http://www.mssqltips.com/sqlservertip/1050/simple-way-to-create-tables-in-sql-server-using-excel/, how to write a sql statement and i do not know to make table plz give me detail regarding this sql statement. The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. [' + @Grouping + '].CURRENTMEMBER.MEMBER_CAPTION. Then you have space available to you beyond 8000 characters. [Country Group].CURRENTMEMBER,[Articles]. To learn more, see our tips on writing great answers. And when you try to get the data from OLAP database using Linked server and OPENQUERY function the query in the nvarchar(max) variable is reduced to nvarchar(8000). Let's say we want Important Run time-compiled Transact-SQL statements can expose applications to malicious attacks. Given below is the script. Thanks for contributing an answer to Database Administrators Stack Exchange! Que cuidados debo de tener en cuenta para que esto funcione correctamente a tan bajo nivel? Basicallythe solution is that you need to cast the characters as VARCHAR(MAX) before insertion and insert it again. Problem. This is the topic of this thread, I hope to seek one solution to resolve the issue when the query has 8000+ data. Explanation: Let me explain the solution step by step. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. set @ParmDefinition = N'@StartDate_str DATE'; EXEC sp_executesql @SQLString, @ParmDefinition, @StartDate_str = @startdate; -- narrow down the report based on the requester or authoriser, or both, if((@requster is not null) and (@authoriser is null)), Select [Account Number], [Shareholder Name], , [Current Holdings], [Affected Register], from #finalrecord Where Requester like '%'[emailprotected]+'%', order by [Change Date] asc, holder_id asc, else if ((@authoriser is not null) and (@authoriser is null)), from #finalrecord Where Authoriser like '%'[emailprotected]+'%', else if ((@requster is not null) and (@authoriser is not null)), from #finalrecord Where Requester like '%'[emailprotected]+'%' and Authoriser like '%'[emailprotected]+'%', from #finalrecord order by [Change Date] asc, holder_id asc, IF(@changeType not in ('edmms', 'change of name', 'change of address', 'correction of name', 'correction of CHN')). SQL injection vulnerability in ChronoScan version 1.5.4.3 and earlier allows an unauthenticated attacker to execute arbitrary SQL commands via the wcr_machineid cookie. How does SSMS connect to a server's database without the instance name? could in example 1. @Str is the text that is longer than 8000 characters. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. [Shop by Model].[Brand].&[7FAM].&[Retail].&[07U],[Shop]. much do whatever you need to in order to construct the statement. How do you get out of a corner when plotting yourself into a corner. . LAST_NAME, FIRST_NAME, POSTAL_CODE. But how do you do this from within a SQL Server [Shop by Model].[Brand].&[7FAM].&[Retail].&[0D8],[Shop]. I must develop a stored procedure in a dynamic way. Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2, How to return only the Date from a SQL Server DateTime datatype, How to concatenate text from multiple rows into a single text string in SQL Server, Manipulate VARCHAR variable larger than 8000 characters. It will print the text passed to it in substrings smaller than 8000 characters. Problem is that nvarchar(max) + varchar(y) = nvarchar(max) + nvarchar(4000) ; SQL will convert your varchar(y) into nvarchar(y) or nvarchar(4000) if y is greater than 4000 and lesser than 8000, truncating your string ! Before print convert into cast and change datatype. In dynamic Sql, , I reach the varchar limit is 8000 characters. SQL NVARCHAR and VARCHAR Limits. If what you are trying to accomplish is to do this in Management Studio, the script below might help. I agree this is not the best method for writing codeand should only be used as a last resort and SQL injection should always be a concern regardless of what methods are used. From that post: This very simple procedure is designed to overcome the limitation in [Shop by Model].[Brand].&[7FAM].&[Retail].&[0DC],[Shop]. Literal Strings are those you hard-code and wrap in apostrophe's. Also, I would be VERY hard-pressed to call the first example dynamic SQL. = dbms_sql.execute(l_cursor); l_min_emp_id := l_min_emp_id + l_increment; Is there a wayto 'continue' the execution ofa query/program after generating an output through SELECT statement. - RelativitySQL Jan 30, 2021 at 21:25 Show 1 more comment 7 DECLARE @sql VARCHAR (max) SET @sql = 'SELECT * FROM myTable' Exec @sql Note: Print (@sql) Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Whenever I write dynamic SQL, I typically include a PRINT @DynamicSQL statement in a comment right above the EXEC sp_ExecuteSQL @DynamicSQL statement so that the dynamic SQL can be easily read and debugged when needed. Step 4 : Look into using dynamic SQL in your stored procedures by employing one of Data Model and a Brief Introduction How to count more than one time with different conditions? That's an average of at most 200 characters per line - but remember, spaces still count! If you need to go beyond 4,000 characters with the NVARCHAR data type, you need to use NVARCHAR (max). I want to store the result of a dynamic query into a variable, assuming the query returns only 1 value. in our case, this sql query is located in the SP which we can't control the the table structure. This was added in SQL 2008, and with SQL 2005 you will need to split this into DECLARE + SET. + 'hc.change_date BETWEEN' + ' ' +'@StartDate_str ' + ' AND ' + ' @EndDate_str'); set @ParmDefinition = N'@ccId int, @StartDate_str DATE, @EndDate_str DATE'; EXEC sp_executesql @SQLString, @ParmDefinition. [Shop by Model].[Brand].&[7FAM].&[Retail].&[0BF],[Shop]. [Season] AS [Articles]. While developing the SSRS report we have to create a stored procedure using MDX query for this we have to hold the MDX string into particular variable but the variable having NVARCHAR(MAX) does not allow string character to be more than 8000 BUT the size of our MDX query string increases while passing multi select Shop parameter value. [Store Transaction Motive].&[U-]}, [Store Transaction Suspended]. [Stores2 Sales Value Net exc VAT - Base]), AS Sum(TopSellers, [Measures]. What is the purpose of non-series Shimano components? I just discovered another benefit of using sp_executesql to execute the dynamic SQL. Each DB has the same set of table names, e.g. Regards! Should you identify any content that is harmful, malicious, sensitive or unnecessary, please contact me via email (imran@raresql.com) so I may rectify the problem. El Proc B Devuelve el Total de esta operacion al Proc A. Espero ser claro. Most probably the recommended solution would also help to maintain and troubleshoot How to get fast answers to your question[/url] How to post performance related questions[/url]Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]. [All],' + @ArticleFilter + '), MEMBER [Measures]. SQL Server DBMS. Although generating SQL code on the fly is an easy way to dynamically build In oracle, we use a LONG data type that can handle this, but i am not sure if there is any other data type in t-sql that can do this. I am trying to pass a string like 2151 characters in length, to the EXECUTE IMMEDIATE command. But we can use your suggestion if the table stucture before insert data. Conclusion : [Shop by Model].[Brand].&[7FAM].&[Outlet].&[0ZW],[Shop]. I can execute the query which having chars more than 8000. How Intuit democratizes AI development across teams through reusability. Dynamic SQL is a programming technique that enables you to build SQL statements dynamically at runtime. You could set up a loop and display "chunks" of the @str data, using an 8,000 character chunk size. [Stores2 Sales Quantity]), MEMBER [Measures]. However, I am usually executing multiple "commands", not 1 single command greater than 8000 chars. Can anyone tell me if there is a way to get around the 8000 character limit for executing dynamic SQL statements? I have a SQL which was more than 21,000 characters. It's because that query has some local variables and temporary tables. Well I ran to this before (in SQL 2005) and I can tell you that you have two options: 1 - Use the sys.sp_sqlexec stored procedure that can take a param of type text (IMO this is the way to go). Tag: Executing Dynamic SQL larger than 8000 characters; 4. You can parse the data into ten variables of 8000 characters each (8000 x 10 = 80,000) or you can chop the variable into pieces and put it into a table say LongTable (Bigstring Varchar(8000)) insert 10 rows into this and use an Identity value so you can retrieve the data in the same order. [Shop by Model].[Brand].&[VANS].&[Outlet].&[0SG],[Shop]. Posted in Solutions, SQL SERVER | Tagged raresql, SQL, SQL Server, SQL SERVER - How to store more than 8000 characters in a column | 1 Comment. 2. Extending this suggestion - you can also execute a string at the remote end with EXECUTE AT: EXEC('TRUNCATE TABLE mydb.dbo.' The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup, How to get the current date without the time part. Print 'THE SPECIFIED TYPE OF REPORT [' [emailprotected]+ '], BY THE USER IS INVALID, PLEASE CONTACT SYSTEM ADMINISTRATOR!!! So put all your data in @SQLString variable and execute like below: Thanks for contributing an answer to Stack Overflow! For this example, we want to get columns AddressID, AddressLine1 and City where The examples below are very simple to get you started, but Styling contours by colour and by line thickness in QGIS. SQL Server Agent; Management Studio; Backup; Restore; Availability Groups; Webinars; All Categories; T-SQL. Here is the error: The character string that starts with 'SELECT .' is too long. declare @myparam int = 6; select @myparam, AVG(MyValue) OVER (ORDER BY MyDate ROWS BETWEEN @myparam PRECEDING AND 0 FOLLOWING) myval. Executing Dynamic SQL larger than 8000 characters. So if you are dealing with a string of say 80,000 characters. DECLARE @Result DECIMAL(12,2) dynamically build the query, but you are also able to use parameters as you This blog/website is a personal blog/website and all articles, postings and opinions contained herein are my own. '; your solution is very simpe and usefulI like ir so much. Login to reply, The "Numbers" or "Tally" Table: What it is and how it replaces a loop, Increase length of NVARCHAR(MAX) more than 8000 Character. The data entered can be 0 characters in length. For fast, accurate and documented assistance in answering your questions, please read this article.Understanding and using APPLY, (I) and (II) Paul WhiteHidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden, NVARCHAR(MAX) supports a huge string 2^31 - 1 bytes(~1+gig nvarchars )however, many applications, specifically SQL Server Management Studio, will only display the first 8000 characters of the string no matter what the value is, so if the data is stored in a varchar(max)/nvarchar(max), it defaults to display only the first 256 characters, but if you change the setting pictured below to a largest value, it still will only display the first 8K chars(this is for performance reasons, so grids don't freeze up). Try using use nvarchar (max) - Simon Aug 23 '17 at 16:59. solution simple and efficient You did not mention using :SETVAR in scripts running in SQLCMD mode. Thanks a lot. if the @sqlquery has more than 8000 character, how to overcome it? @Roberto - this isn't exactly true. to be built correctly and therefore run. Then you could just call the sproc or the view instead of using such a long statement. My problem is my query (it's only one single query) that I want to feed into the @sql variable uses more than 25 table joins, some of them on temporary table variables, incorporates complex operations and it is hence much more than 8000 characters long. #1631102. initally u r declared datatype for @city, then why u are using the samething at EXECUTE statement like. 5. Maybe your script does not affect any rows. To run a dynamic SQL statement, run the stored procedure sp_executesql as shown below : Use prefix N with the sp_executesql to use dynamic SQL as a Unicode string. Viewing 15 posts - 1 through 15 (of 15 total), You must be logged in to reply to this topic. There are a number of possible issues here, the most likely is that you are using other variables in the construction of the string, and they are not all nvarchar(max). Good question/answer about nvarchat/varchar, To explicitly say to system that this is nvarchar put N before single quoted expression. If that truly is dynamic SQL, then every stored procedure I've ever written is done using dynamic SQL (okay, maybe 95%, since perhaps I've written a few that don't have parameters. Please assist me with this problem i seemed not knowing way forward! This could potentially open [' + @Grouping + ']*[Articles].[Season].[Season],[Articles]. [Fiscal Hierarchy].&[2012031]', set @Currency=N'[Reporting Currency]. missing from above Ntext can be used in a table but not in a variable, only in a table sorry I rush typed the above. You really should mention that in more significant detail than just the next steps. Help me Please, Here are a few options: We will use the I have a table in ehich column having some dml commands. [Shop by Model].[Brand].&[7FAM].&[Retail].&[0D9],[Shop]. declare @a varchar (8000),@b varchar (8000),@c varchar (8000) select @a='select top 1 name,''',@b=replicate ('a',8000),@c=''' from sysobjects' exec (@a+@b+@c) Friday, February 2, 2007 4:59 PM 0 Sign in to vote Is it possible to rotate a window 90 degrees if it has the same length and width? 1 2 3 4 5 6 your code checks for any potential problems before just executing the generated When concatenating long strings (or strings that you feel could be long) always pre-concatenate your string building with CAST('' as nVarChar(MAX)) like so: What a pain and scary to think this is just how SQL Server works. Some names and products listed are the registered trademarks of their respective owners. [Shop Model].&[Outlet]} ON COLUMNS, FROM (SELECT {strtoset("{' + @Stores + '}")} ON COLUMNS. document.getElementById( "ak_js_1" ).setAttribute( "value", ( new Date() ).getTime() ); Enter your email address to follow this blog and receive notifications of new posts by email. All help would be greatly appreciated. Is there any way to run the query more than 8000 character via openquery. Consider some static SQL DML (Data Manipulation Language) approaches including. So the problemis, on submitI have to build an sql query during run timefor my asp.net application tosearch for records in my Database onlyfor theentries which the user has eneterd. El problema es que en el (SSMS) funciona. [Stores2 Sales Value Net inc VAT - Base],[Measures]. Let me create a table to demonstrate the solution. into your WHERE clause of your SQL statement in Microsoft SQL Server. I'm able to see verify length and output of each. :) Make all '@scriptN' nvarchar(max) and concatenate them in on '@SQLStrin'g and try to execute this like shown below. If you preorder a special airline meal (e.g. @Manish Kumar - here is simple code to do this: create table #temp (sqlcommand varchar(500))insert into #tempselect 'drop table AccountID_55406' union allselect 'drop table Accountid_70625', DECLARE db_cursor CURSOR FOR SELECT sqlcommand FROM #temp ORDER BY 1, OPEN db_cursor FETCH NEXT FROM db_cursor INTO @sqlcommand, WHILE @@FETCH_STATUS = 0 BEGIN PRINT @sqlcommand EXEC (@sqlcommand) FETCH NEXT FROM db_cursor INTO @sqlcommand END. In DBMS_SQL.PARSE you can use VARCHAR2A or VARCHAR2S to process Large SQL. I only want to create one query has 8000+ charaters, and prove the openquery doesn't work. There shouldn't be a problem executing sql statement larger than 8000 via exec(). [SQM]AS [Measures]. 4. As you can see, this time it has inserted more than 8000 characters. [All], ' + @ArticleFilter + '), AS Iif( "'+ @DetailLevel +'"= "C",[Shop]. Step 2 : If the length is more than 8000 characters. Could you please give me a sample to create that SP? Step 5 : [' + @Grouping + ']. code at runtime. I have been having the same problem, with the strings being truncated. PHP, Java However, I think you've done a bit of disservice to the community for not going into the pros and cons of each. I know somebody has run into this before. Thanks for the help! So you can't use: And then call SELECT * FROM #TMP. declare @.a varchar(8000),@.b varchar(8000),@.c varchar(8000)select @.a='select top 1 name,''',@.b=replicate('a',8000),@.c=''' from sysobjects'exec(@.a+@.b+@.c) varchar(max) also should work just fine - could you please try something like the following? [' + @Grouping + ']. In my last tip, I showed how to use T-SQL to generate HTML for fancy calendar visuals overlaid with event data from another table.As an extension of that tip, let's now look at simplifying parts of that query by caching the date information in a calendar table to streamline the outer queries and avoid complications caused by different DATEFIRST settings. Es ahi donde se queda en un proceso indefinido. Mil Gracias por tu ayuda y abrazos desde medellin, colombia. Obviously the dynamic query is going to be more complicated, in this example there is no reason to use sp_executesql. This can be done quite simply from the application perspective Please tell me how to execute a select string that has more than 8000 char. - Becker's Law My blog My TechNet articles It's not the problem. [Shop Model] AS Iif("'+ @DetailLevel +'"= "C",[Shop]. To learn more, see our tips on writing great answers. What values are you passing in and what values to you want to see output? you start to manipulate the overall query string. Why don't you try it and tell us. With that, we have reached the end of this article. The Transact-SQL statement or batch can contain embedded parameters. the query itself is changing based on parameters that are being passed to it--such as the source table in the FROM clause changes based on whether you are pulling data from US or UK), then building the code in a stored procedure, and executing it using sp_executesql is by far the safest way of building and executing your code. Abhijit Jana. [Country Group].CURRENTMEMBER.MEMBER_CAPTION,[Shop]. + @test1 + ' from Table2 t2 inner join Table1 t1 on t1.Hdl_Nr = t2.Hdl_Nr' print @select2exec (@Select2). Dynamic SQL is a feature that helps minimize hard-coded SQL. Or use SELECT if the string is more than 8000 characters. The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. But CF quietly onboards new related technologies (like microservices) and remains one of the most secure server-side platforms in the market. [Stores2 Sales Value Net exc VAT - Base]), [Articles]. Let me explain the solution step by step. Fantastic Greg, congratulations. This is slow and less secure than the other methods described above. not working even like this exec(@str1+@str2+@str3). You can also deploy your python app after containerizing the application using Docker & Azure container registry, but that's a lesson for another day. Msg 137, Level 15, State 1, Line 6 Do roots of these polynomials approach the negative of the Euler-Mascheroni constant? :SETVAR TBL MyTableINSERT INTO dbo.$(TBL)_copySELECT * FROM dbo.$(TBL)_original:SETVAR SRV MyServer:SETVAR DB MyDatabaseSELECT * FROM $(SRV).$(DB).dbo.$(TBL), You can write multi-server scripts, like a database copy. You had an extra ) in the code. Thanks a lot Sergiy.