Sql server loop through list of strings


Sql server loop through list of strings. I discovered while googling that the way to do it is with an in memory table and the best I could come with is this. I can get a list of the tables from each schema using : May 9, 2024 · SQL string functions manipulate string (including text and alphanumeric) values. Mar 25, 2014 · I am trying to loop through a list of email addresss with a SQL stored procedure -Get the first part of the email addresses and query another table where the part matches a a field DECLARE @channe Dec 20, 2017 · I have written a SQL query that joins two tables and calculates the difference between two variables. SQL String Functions: ASCII and CHR. We can call the STRING_SPLIT () function again to add this data as column id 5 and column id 6. Marc Now: I want to add a list of strings, List<string>, to the parameter set. Mar 31, 2016 · You could do it easily in pure SQL. Feb 11, 2010 · I'd like to loop through a list of strings and execute a function/procedure with each string as the argument. SQL String Functions: SUBSTR. Aug 15, 2017 · 2. This means they return the same value any time they are called with a specific set of input values. These will align with the order they I have a list of value ('2021-01', '2021-02', '2021-03')For each element in the list, I want to run a chunk of sql code. OUTPUT. there are multiple ways of doing it, see Split comma delimited string into rows in Oracle. Use Transact-SQL Statements to Iterate Through a Result Set There are three methods you can use to iterate through a result set by using Transact-SQL statements. print SUBSTRING(@str,@i,2) I'm just not sure how to loop through that result set to create the string, i'd want the string to just end up as. Then, you can try the following: DECLARE @View VARCHAR(200), @Query VARCHAR(MAX) DECLARE YourView CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR SELECT name FROM sys. Give me some ideas, I can carry on from there. and s. There are three methods you can use to iterate through a result set by using Transact-SQL statements. + case OPTION2 when 1 then ' OPTION2' else '' end. EXEC usp_cols 'col1, col2, col3'; I want to split this string to list of strings in the stored procedure, so that it converts to 'col1', 'col2', 'col3' in the stored procedure to use it in the LIKE statement: WHERE colname LIKE('col1', 'col2', 'col3') SQL Server IN operator overview. I have a list of strings which I would like to iterate and set as a variable in sql, I want to iterate a list of these strings ["one","two","three","four"] and then set each of these strings as a variable for a query. Jun 23, 2022 · STRINGTOTABLE is user define function which will parse comma separated data and return table. DECLARE @id INT. It can make code easier to read and understand for SELECT, UPDATE or DELETE SQL commands. WHILE (LEN(@columnNames) > 0) BEGIN. Check out this interactive course on Standard SQL Functions if you want more hands-on practice than this article includes. So i have a list of like 300 strings. Then build up the script: Declare @sql varchar(max) = '' declare @tablename as varchar(255) = 'test' select @sql = @sql + 'select [' + c. You can just use sql:variable to satisfy nodes() requirement of a string literal argument to query sub elements of a specific node iteratively. Jan 6, 2022 · 2. thanks I think this is the easy way example to iterate item. Orders ORDER BY ID. SqlClient). SELECT TOP 1 @id = id FROM dbo. Jan 13, 2013 · This can change from release to release or even within a particular server version due to changes in the query plan. Strings in a Column to Select Query Loop May 23, 2023 · The following scalar functions perform an operation on a string input value and return a string or numeric value: All built-in string functions except FORMAT are deterministic. 7. Jan 27, 2015 · 1. I'm asuming the your table name is "Table", the result where you will find the strings you want would be the column named A_B, each record will have two things in each record, one would be the string you asked for, the other column 1. Use the loop to loop over the db and/or server names. Dec 2, 2011 · The ProcessListSQL procedure take two parameters. SUBSTRING(OfferString, 1, 81) AS Offer1, SUBSTRING(OfferString, 82, 81) AS Offer2. The IN operator is a logical operator that allows you to check whether a value matches any value in a list. For more information about the enumerator, see Foreach Loop Container. ALTER PROCEDURE [dbo]. SELECT ROWNUM,CAST(dbo. name + ''' from [' + t. It is unclear if that is really required for your question. True or False. May 7, 2024 · OPENJSON converts JSON into a set of rows and columns. SQL: SELECT. You need to provide a set of values, a string is not "parsed" in any way or treated as a comma-separated list. Consider this SQL query: SELECT *. Inside the loop, the task will populate with variable (s) from the current row. declare @UserIds table (UserId INT) declare @CurrentUserID INT. A + '_' + Table. Now i want to create a View that loop through each B. Note: If you are using SQL Server you would be better served using: WHILE EXISTS(SELECT * FROM #Temp) Using COUNT will have to touch every single row in the table, the EXISTS only needs to touch the first one (see Josef's answer below). Sep 30, 2013 · foreach part in array string_to_array('one,two,three', ',') loop -- do something with part end loop; sql fiddle demo documentation about looping through arrays . You can use dynamic SQL for this so long as you're using this in a systems administration context and not out in the wild. In this post, we’ll look at five ways Nov 25, 2020 · I have produced a table in SQL with a list of tables. But for this to work you should have unique identity column in a table. select @i = @i + 1. Your <string to split> can represent Dec 21, 2009 · Solution. Mar 29, 2011 · The Foreach Loop in SSIS is used for iterating over a list of objects. I prefer STRING_AGG() if you are using SQL Server 2017 or higher, but using XML to concatenate strings is one option if you are unable to upgrade to SQL Server 2017. Feb 6, 2013 · In my stored procedure I have an incoming array of strings (e. SQL String Functions: CONCAT. The messages sent from the web server to the database server would look something like this (pseudo-code messages): SET @counter = @counter + 1. An example is given below: declare @str varchar(5)='house'. The second parameter is a string that contains the SQL that will be executed with each of the objects in the first parameter. We’ll show this later in the article. Below is the code. Jan 30, 2017 · SQL aggregates work on groupings of data. set @db = (select top 1 name from #dbs where run = 0 order by name) set @sql = '. Jan 31, 2020 · Database developers often need to convert a comma-separated value or other delimited items into a tabular format. Use it to run any SQL query on the returned data, or insert it into a SQL Server table. If you want your value in a single row, you already have it; as it is. Whether this is a better way is up to you: DECLARE @CNT INT = 0; DECLARE @DAYSUBTRACT INT = 0; DECLARE @ACCOUNT_ID INT; CREATE TABLE ##ACCOUNTS (ACCOUNT_ID INT NOT NULL); Jun 21, 2018 · There are many methods for concatenating strings in SQL Server, and many blog posts explore and vigorously debate these options. SELECT *. Is there a way to iterate through this list of tables, something like this? Aug 28, 2014 · If you are using SQL Server, you can use a Table variable to loop through records. CREATE DATABASE TEST. e. You could do a concat type query. I would like to loop through this list and then build a string which will serve as a condition in a WHERE clause, like this. Table. Configure the ForEach task instead. SQL> DECLARE. Now I want to loop through the Json array by index to get a specific value. I need to figure out how to execute the SP for each id. I need to build a function to replace multiple substrings for all rows in a table. That way I could execute some query on the table variable in one part of the procedure, and then later execute some code for each row in the table variable. Such an antipattern can involve the creation of a dynamic SQL string in the application layer or in Transact-SQL. Dec 13, 2016 · If you want to select only certain values from a single table you can try this. Sep 27, 2012 · One way to do this is using cursors. For more information about function determinism, see Deterministic May 2, 2014 · Please don't use loops for things like this (I'd also reserve recursive CTEs for scenarios where you have much less control over things, like hierarchies). CREATE TABLE [dbo]. So the test, in the example above, would Jul 5, 2020 · I need to loop through each value present in the variable @columnNames and use it in a dynamic sql. You can even extend the functionality for The ConnectionString is the connection string itself. from Table. You cannot rely on this behavior even if there are workarounds. SELECT (Table. You can use string_split to return a set of values, for example. select top 1000 YourField from dbo. Nov 3, 2010 · What I'd like to do is loop through the varchar variable, moving forwards one character at a time, testing if 4 characters are in the company name field. SET @MyCursor = CURSOR FOR. A resultset, like a table, has a fixed schema (meaning datatype and number of columns). where seqnum = 1; Note: you can filter on particular ids, if you want. And the list of 300 strings, is a part of a column Nov 15, 2017 · I've seen a lot of javascript stack questions around this, but nothing specifically related to SQL Server. Mar 19, 2015 · Loop through a character in sql. Split(@String nvarchar(4000), @Delimiter char(1)) RETURNS @Results TABLE (Items nvarchar(4000)) AS. SQL Server 2016 added STRING_SPLIT which is faster than all previous techniques. I figure that i'll need something along the lines of : DECLARE @tableName varchar(50) DECLARE @schemaName varchar(50) For now lets call the schemas "A" "B" and "C". ' and extract the column names. declare @i int = 1. There are also benefits to use a WHILE loop compared to a cursor. A quick way to turn your varchar variable to a table (array of values) is to have your FirstName variable as a whole varchar first and then use the STRING_SPLIT method. The stored procedure call that produces the above table is; exec cfn_PlanningGoalGetType 0,'xmlString'. Nov 6, 2015 · 1. For you requirement, you need to use the SUBSTRING () function along with WHILE statement. For example, my stored proc query goes like this: I would like to be able to use a table variable in the same manner as a cursor. that may get inserted in a string. DECLARE @columnNames NVARCHAR(MAX), @dSql NVARCHAR(MAX) SEt @columnNames = 'SCHEDULEDSTART, SCHEDULEDEND'. select @i = 0. These will align with the order they Jul 29, 2014 · A "list" or "array" in SQL Server is always. Use cursor to loop through the rows in specific order and concatenate the values 2. Conclusion. SQL String Functions: TRIM. A new pattern I've seen emerging is to replace splitting comma-separated strings with the new OPENJSON functionality introduced in SQL Server 2016. Here is the query which filters the IDs in product_table which are in the range between listtable. Jun 23, 2020 at 16:34. The first is a comma delimited string that contains the list of objects that will be cycled through. I want to iterate that list in the main package executing two other packages for each connection: Sep 28, 2012 · Well, in case of a known number of columns, you can do: SELECT. Also known as text functions in SQL, string functions take one or more string values as an argument and return a modified string value. I know looping over the whole database 48 times is quite stupid, but SQL is not my wheelhouse. FETCH NEXT FROM db_cursor INTO @name. GO. However, with the introduction of the STRING_AGG function in Transact-SQL, the process of concatenating . First, create the table in SQL Server Management Studio (SSMS): id smallint, email varchar(50) ) Next, add this code to generate ids from 1 to 100 and random emails: By using T-SQL and cursors like this : DECLARE @MyCursor CURSOR; DECLARE @MyField YourFieldDataType; BEGIN. This can be done quite simply from the application perspective where the SQL statement is built on the Jun 10, 2009 · It would be in efficient for the SQL code being executed on the web server (where your SQL script may originate from) to have to make single requests to the back end to delete each item in the table in a loop. Nov 26, 2012 · LEFT () function in SQL Server will only print the number of characters specified from the left side of the string. If you omit the providerName= attribute from your connection string in config, it defaults to SQL Server (System. Before SQL Server 2017, developers and database administrators had to rely on complex workarounds to achieve this. This data is delimited by a single space. *. 'ECSO10ARR', ECSO11ARR', ECSO12ARR'). I first create a temporary table . I CANNOT alter the stored procedure. name + '] group by [' + c. 2 str VARCHAR2(100) := 'PEBO,PTGC,PTTL,PTOP,PTA'; Azure DB, Azure Data WH and from SQL Server 2016, you can use STRING_SPLIT to achieve a similar result to what was described by @sparrow. May 6, 2015 · it is possible to create a @parentList varchar(max) variable and return result as a string '6,5,4,3,2,1' and split it on client-side, but that format is not useful in db The Foreach from Variable Enumerator enumerates over the items in a list that is passed to it in a variable and performs the same tasks on each item. SQL String Functions: REPLACE. Jul 28, 2016 · I have a stored procedure that query the database and store the result in a Json variable. Mar 4, 2022 · In this simple example, we will create a table named emails with an id and email columns and add 100 fake ids and emails by using a WHILE loop. Jun 2, 2021 · In is a operator that works on a set, not a string. table. One method is the use of temp tables. END. However, with the introduction of the STRING_AGG function in Transact-SQL, the process of concatenating In order to be able to use the STRING_SPLIT function, we should change the compatibility level of the database to 130 using the below ALTER DATABASE T-SQL statement: USE [master] GO ALTER DATABASE [MSSQLTipsDemo] SET COMPATIBILITY_LEVEL = 130 GO. The ONLY guaranteed mechanism are the following: 1. Jun 27, 2023 · Use Transact-SQL Statements to Iterate Through a Result Set. WHILE @id IS NOT NULL. select distinct(*) from table_name where table_field in (1,1,2,3,4,5) eg: select first_name,phone_number from telephone_list where district id in (1,2,5,7,8,9) if you want to select from multiple tables then you must go for UNION. For more info about what you see in the output of the JSON_ARRAY function, see the following articles: How FOR JSON converts SQL Server data types to JSON data types (SQL Server) Jan 1, 2010 · Learn how to use FOR EACH loop in SQL Server with examples and tips from Stack Overflow, the largest online community for programmers. Do I run a select * from resources first and then loop through each resource and do a separate query per resource to get the list of applications for that resource? Jul 6, 2021 · In some applications, having hard coded SQL statements is not appealing because of the dynamic nature of the T-SQL queries being issued against the Microsoft SQL Server DBMS. So, for the example above you have a one dimensional list, List<Dog>, as an input to the loop. views OPEN YourView FETCH NEXT FROM YourView INTO @View WHILE @@FETCH_STATUS = 0 BEGIN SET @Query = 'SELECT '''+@View+ Jan 1, 2015 · So we need to extract numbers from each PX and get the values between them and append PX. DT) AS DurationMS FROM #test_list AS begins JOIN #test_list AS ends ON begins. Jan 3, 2023 · In this article we will see how to create a Array variable in SQL and how to iterate through it to process records in database. Data. System. Below is sample data and T-SQL: Data. I have tried the following: select fileName. The third column contains the complete HTTP call. While loops use less locks than cursors. SQL Server has a couple of undocumented system stored procedures in the master database, which allow you to loop through all or selected databases using the sp_MSforeachdb system stored procedure or loop through all or selected user tables using the sp_MSforeachtable system stored procedure. tables t on c. Aug 27, 2021 · How do I loop through a VARCHAR(100) and remove the commas? Each ID should be used uniquely in the WHERE Clause. SQL functions used for manipulating strings, commonly called string functions, are among most important SQL’s tools. Less usage of Tempdb: While loops don’t create a copy of data in tempdb as a cursor does. Aug 22, 2013 · Now, I thought to create a script to insert all of them and as a c# developer I thought I need to initialize a list with their names. -- Table variable to store the list of user ID. Because of this, sometimes there is a need to dynamically create a SQL statement on the fly and then run that command. it violates first normal form in database design as you have multiple values in a single column. se Jun 15, 2020 · For us, the most important facts are: SQL Server implements the WHILE loop allowing us to repeat a certain code while the loop condition holds. you could split the string into rows then the join becomes trivial and then use forxmlpath to recreate the permissions in a comma seperated list but ideally a RDBMS shouldn't store data this way just for this reason. If, for any reason, we need other loops, we can simulate them using a WHILE loop. ListContents value, extract the number, and finds its corresponding "ProductID" "Name" "Price" from Table A。. id - 1 ORDER BY 2; It is clear that string solution wins : Another way of iterative solution is WHILE loop. B) AS A_B, COUNT(*) AS RowsCount FROM Table. don't know if that helps or is clear enough but any direction would be Dec 9, 2013 · You can use dynamic SQL and get all the column names for a table. I am not sure how to get the LOOP to search for multiple '. May 2, 2024 · Here is a SQL Server cursor example from this tip, Simple script to backup all SQL Server databases, where backups are issued in a serial manner: FROM MASTER. Recycling code from @sparrow. USE [Test] GO. udf_GetNumeric(range_end)AS INT) RTO1. To get the current item in the list you need to specify a variable mapping to index 0. dbo. While loops are faster than cursors. If you had a two dimensional list, lets say List<Dog,Owner> then you would retrieve the Jul 13, 2020 · Table B [Favorite] Columns: ListID, ListName, ListContents. . There still could be a need to query sub elements which the answer to this question would not solve. Thanks. group by ID. [StringRetrival](. Or an antipattern can be achieved by using the LIKE operator. select @input = '123', @output = ''. I have long advocated avoiding splitting strings by using table-valued parameters (TVPs), but this is not always a valid option; for example, PHP drivers do not handle this feature yet. Jul 29, 2021 · Now that it is being updated to using a delimiter (~) to parse out each field within one column, I'm not sure how to extract the data and write them to individual fields in another table. MyName + " ->". Nov 6, 2019 · The syntax of the SQL While loop is as follows: The while loop in SQL begins with the WHILE keyword followed by the condition which returns a Boolean value i. Now the compatibility level of the database is modified to 130 to use the STRING_SPLIT function. This is the slowest way possible to split strings. Gordon's approach is certainly superior; nevertheless, it is still possible to convert your approach to one that doesn't require a cursor. id = ends. Generally, it will not change performance characteristics. And you are definitely gonna need dynamic SQL, so first go to this link. declare @FirstName varchar(100) select @FirstName = 'John,Sarah,George'. ) t. It is the Tab Control Character with ASCII 9. SQL Server compatibility level 130, and subsequent versions, support a string_split () function to convert delimiter-separated values to rows (table Sep 18, 2014 · 1. Ask Question Iterating a SELECT statement in SQL Server 2008 using a WHILE LOOP. We want to determine if the call was a POST or a GET. An important note here is, I cannot INSERT or CREATE a table in this DB as this is a production database. Jul 21, 2023 · In SQL Server, data manipulation often involves aggregating and combining values from multiple rows into a single string. Jan 4, 2021 · This @variable could be a string list representing column names, such as. g. I wanted to iterate through this list and run a SELECT statement with each string. DT, ends. You can use the function JSON_EXTRACT() to get the the age and convert it to a numeric value by adding 0: SELECT *. Apr 19, 2018 · INSERT INTO table (UserId,ProductId) VALUES(@UserId, @value) In fact, you should consider taking productIDs as an array. One of these will hold the staging table name and the other will hold the real table name. Something like the following will aggregate the entire dataset that is returned as no grouping is applied: select sum(Col) as Total. With this method, you create a snapshot of the initial SELECT statement and use it as a basis for cursoring. Jan 24, 2022 · SELECT begins. CREATE TEMPORARY TABLE RESULT Jul 21, 2023 · In SQL Server, data manipulation often involves aggregating and combining values from multiple rows into a single string. The body of a while loop in SQL starts with a BEGIN block and ends with an END block. Apr 5, 2012 · How to loop through comma separated list in SQL? I have a list of ID's and I need to pass these ID's to a stored procedure. This function can be very useful to find and replace characters like Tabs, LineFeed etc. The ProviderName is the name of the provider for the connection, e. I want to loop through each entry under 'table_name' and return a 1 if that table has a value in a specific column or 0 if that table does not have a value in a specific column. . + case OPTION1 when 1 then ' OPTION1' else '' end. Also, rather than hard-coding a solution, I would really prefer to loop through connection strings, as I have a bunch of ADODB connections pointing to SQL Server. Firstly the fact that you want to loop in SQL, however, SQL is a set based language. 1. where StatusID = 7. Result should be like: Jul 19, 2017 · 1. WHERE user_id IN (SELECT value FROM STRING_SPLIT( @user_id_list, ',') Simple and effective way of accepting a list of values into a Stored Procedure Nov 6, 2009 · So I have a table with a single nvarchar column with a list of Sql Server OLEDB Connection Strings in it, all that actually differs between them is the database name. while @i<len(@str) begin. Delimiters include pipe “|”, hash “#”, dollar “$” and other characters. Orders WHERE ID > @id ORDER BY ID. The fastest way (apart from SQLCLR) uses XML. + FROM. securityDepartment in (select value from string_split('value1;value2;value3',';')) answered Jun 2, 2021 at 10:22. FROM tablename. Inside the FELC I have a final Execute SQL Task that is a simple insert statement that inserts the variables into the SQL server. name + '] order by 2 desc; ' from sys. 4. So put your values into a table (temp table, table variables, table-valued parameter) and then use proper T-SQL joins to get what you need. name + '],count(*) as ''' + c. WHERE yearfield LIKE 'ECSO10ARR%' OR. Jun 23, 2020 · STRING_SPLIT separates a delimited scalar value into rows. Use the object variable from the Execute SQL Task as the ADO Object Source Variable. Example: SELECT * from aTable where accountName = eachItem. select ''' + @db + '''. What I need to do is accept a string value and do a loop over the string multiple times t Jun 7, 2021 · We seem to have 2 problems here. Don't use script tasks to shred objects into strings. from (select t. as my parameter value. JOIN STRING_SPLIT('1,2,3',',') ON value = ProductId; The preceding STRING_SPLIT usage is a replacement for a common antipattern. I have simplified it here to show you the concept - it should be enough to get you started. CREATE FUNCTION dbo. Whereas something like this will give you a total for each ID value: select ID. object_id = t. , User_FirstName. The column Value as it is it contains valid JSON data. That's SQL Server's concept of "multiple values". The body of the while loop keeps executing unless the condition returns false. If this were Java or C++, it'd be cake. You can use custom code in a Script task to populate a list for this purpose. Jun 16, 2011 · declare input as varchar(1000) -- Choose the appropriate size. Here we are using the ASCII function to list the ASCII values of each character. String operation to extract the name. May 5, 2021 · A typical method is row_number(): select t. The following shows the syntax of the SQL Server IN operator: column | expression IN ( v1, v2, v3, ) Code language: SQL (Structured Query Language) (sql) In this syntax: First, specify the column or Oct 22, 2021 · Problem. from mytable t. age") + 0 > 30; See the demo. Performance is not a big concern, as this is a one-time operation, but there are 48 mappings and roughly 30,000 rows. However, if you really want to do it in PL/SQL, then you could do it as: SQL> set serveroutput on. For example. object_id where t. I have a database of tables, and i want to iterate through each table in 3 different schema, one schema at a time. Example: DECLARE @Steinar VARCHAR(100); SET @Steinar = "22,45,50,105," I need to use each unique ID in my… Oct 31, 2023 · Pros and Cons of Using a While Loop to Iterate Through Table Rows in SQL Server. May 21, 2024 · Returns a valid JSON array string of nvarchar(max) type. Oct 25, 2023 · The SQL Server NOT IN operator is used to replace a group of arguments using the <> (or !=) operator that are combined with an AND. Sep 21, 2017 · To get the results out of the object variable and insert them into my other SQL server, I use another FELC to iterate through the result set storing each field in a string variable using the variable mappings screen. @sqlString = '1,2,4,11,14'. Try this article uses function to read the comma separated values and return the table. Check the last row in the screenshot above. Dec 3, 2018 · Add a Foreach Loop that is of the Foreach ADO Enumerator type. udf_GetNumeric(range_start)AS INT) NUMBERS, CAST(dbo. SqlClient for SQL Server (and others for other database system). Oct 26, 2017 · This generates a list of table names - these are the tables I want to handle with a for loop. columns c inner join sys. Provide one variable per column, using correct data types. For example: Jul 11, 2017 · 5. I want a while loop iterate through the code and do the procedure for a list of organizations numbers orgnr. PRINT @id. Loops are rarely used, and queries do most of the job. Oct 30, 2013 · 9. name I really want to list Table Name, Field Name, and Field Type (running down one row at a time). declare output as varchar(1000) -- Choose the appropriate size. WHERE name NOT IN ('master','model','msdb','tempdb') OPEN db_cursor. --populate your list of databases through which you'll iterate. a TABLE! That's SQL Server's concept of "multiple values". – Thom A. FETCH NEXT FROM @MyCursor. On the Variable Mappings page, add a string variable at index 1 and 0. while @i < len(@input) begin. *, row_number() over (partition by id order by id) as seqnum. If source databases are all the same you avoid dynamic SQL. Oct 30, 2023 · FROM Product. Loops are bad in SQL; SQL is optimized to work in sets. This list of tables is stored under the column 'table_name'. declare @i int. style, DATEDIFF(millisecond, begins. BEGIN. This data is saved as column id 7. This was setup by clicking From Other Sources > From SQL Server > Server Name > Next . sysdatabases. For example: 2. OPEN @MyCursor. If columns are unknown when you create the query - I'd probably still go that way with some dynamically created SQL. WHERE JSON_EXTRACT(Value, "$. Without making any assumptions, you logically cannot. ,sum(Col) as Total. This means that it performs great at set-based operations but poorly at iterative ones, such as a loop. [specso_WarrantsByZone_Report] @yearval VARCHAR (500), AS. In the below example, four databases are created. 0. ListContents contain a list of IDs, seperated by "," Exp: 1,2,5,6,8. " Apr 13, 2017 · Table of Contents. select @output = @output + 'ABC' + substring(@input, @i, 1) See full list on sommarskog. B. ze ye zm by fi kr kt zo xq gw