You seem to want to use a CURSOR
. Though most of the times it’s best to use a set based solution, there are some times where a CURSOR
is the best solution. Without knowing more about your real problem, we can’t help you more than that:
DECLARE @PractitionerId int DECLARE MY_CURSOR CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY FOR SELECT DISTINCT PractitionerId FROM Practitioner OPEN MY_CURSOR FETCH NEXT FROM MY_CURSOR INTO @PractitionerId WHILE @@FETCH_STATUS = 0 BEGIN --Do something with Id here PRINT @PractitionerId FETCH NEXT FROM MY_CURSOR INTO @PractitionerId END CLOSE MY_CURSOR DEALLOCATE MY_CURSOR
Related Posts:
- Selecting COUNT(*) with DISTINCT
- What is a stored procedure?
- Self Join to get employee manager name
- How do I UPDATE from a SELECT in SQL Server?
- SQL query to select dates between two dates
- When should I use CROSS APPLY over INNER JOIN?
- How can I do an UPDATE statement with JOIN in SQL Server?
- How do I escape a single quote in SQL Server?
- T-SQL split string based on delimiter
- How do I escape a single quote in SQL Server?
- IDENTITY_INSERT is set to OFF – How to turn it ON?
- Column name or number of supplied values does not match table definition
- SQL Server FOR EACH Loop
- Each GROUP BY expression must contain at least one column that is not an outer reference
- DateTime2 vs DateTime in SQL Server
- How to parse XML data in SQL server table
- What is the equivalent of ‘describe table’ in SQL Server?
- Error converting data type varchar to float
- What is the Oracle equivalent of SQL Server’s IsNull() function?
- I want to use CASE statement to update some records in sql server 2005
- Conversion failed when converting the varchar value ‘simple, ‘ to data type int
- Must declare the scalar variable
- SELECT DISTINCT on one column
- Exclude a column using SELECT * [except columnA] FROM tableA?
- Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 4 (Year)
- TSQL PIVOT MULTIPLE COLUMNS
- SQL “select where not in subquery” returns no results
- Equivalent of Oracle’s RowID in SQL Server
- Is it possible to specify condition in Count()?
- SQL Server dynamic PIVOT query?
- Error converting data type varchar
- Temporary table in SQL server causing ‘ There is already an object named’ error
- I want to use CASE statement to update some records in sql server 2005
- How to calculate age (in years) based on Date of Birth and getDate()
- ORDER BY items must appear in the select list if SELECT DISTINCT is specified
- Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
- How can I group by date time column without taking time into consideration
- “select * into table” Will it work for inserting data into existing table
- SUM OVER PARTITION BY
- Update query using Subquery in Sql Server
- Varchar invalid for Sum operator
- LIKE vs CONTAINS on SQL Server
- Case in Select Statement
- Inserting multiple rows in a single SQL query? [duplicate]
- SQL Server: Difference between PARTITION BY and GROUP BY
- Conversion failed when converting date and/or time from character string while inserting datetime
- error, string or binary data would be truncated when trying to insert
- Must declare the scalar variable
- Must declare the scalar variable
- Rename column SQL Server 2008
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- Function to Calculate Median in SQL Server
- What is the use of GO in SQL Server Management Studio & Transact SQL?
- Drop a temporary table if it exists
- How Stuff and ‘For Xml Path’ work in SQL Server?
- Each GROUP BY expression must contain at least one column that is not an outer reference
- Update statement to update multiple rows
- Why does NULL = NULL evaluate to false in SQL server
- Import / Export database with SQL Server Server Management Studio
- Best way to do nested case statement logic in SQL Server
- The multi-part identifier could not be bound
- Get day of week in SQL Server 2005/2008
- incorrect syntax error CREATE VIEW must be the only statement in the batch
- Attach (open) mdf file database with SQL Server Management Studio
- Sql Server string to date conversion
- How can I truncate a datetime in SQL Server?
- Why use a READ UNCOMMITTED isolation level?
- Find all tables containing column with specified name – MS SQL Server
- How to group by month from Date field using sql
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- SQL – The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
- Is there a combination of “LIKE” and “IN” in SQL?
- SQL Server String or binary data would be truncated
- SQL Server IF NOT EXISTS Usage?
- How do you create a yes/no boolean field in SQL server?
- MS SQL compare dates?
- What represents a double in sql server?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- ListAGG in SQLSERVER
- Is there a Max function in SQL Server that takes two values like Math.Max in .NET?
- Regex pattern inside SQL Replace function?
- Subtract one day from datetime
- Get current year in TSQL
- Errors: “INSERT EXEC statement cannot be nested.” and “Cannot use the ROLLBACK statement within an INSERT-EXEC statement.” How to solve this?
- Replacing NULL with 0 in a SQL server query
- SQL Server: Make all UPPER case to Proper Case/Title Case
- How do I query for all dates greater than a certain date in SQL Server?
- Backup a single table with its data from a database in sql server 2008
- Conditional JOIN Statement SQL Server
- Solutions for INSERT OR UPDATE on SQL Server
- What datatype should be used for storing phone numbers in SQL Server 2005?
- Append table to an existing one: SQL Server
- SQL Server – An expression of non-boolean type specified in a context where a condition is expected, near ‘RETURN’
- Filter data based on date in sql
- CASE IN statement with multiple values
- How to truncate string using SQL server
- Pad a string with leading zeros so it’s 3 characters long in SQL Server 2008
- How to dump a Microsoft SQL Server database to a SQL script?