Q 1.How to update mutiple rows using single statement.
Suppose we want to update M as Male and F as Female in Gender Table using single Sql Statement then we use
UPDATE Genderset GenType = CASE GenType WHEN 'F' THEN 'Female' WHEN 'M' THEN 'Male'ELSE 'Unknown' END
2. How to Execute a query which is stored in as table column.
DECLARE @sSQL nvarchar(max)
SET @sSQL = 'BEGIN TRAN; '
SELECT @sSQL = @sSQL + COLUMN_WITH_INSERT_STATEMENT + '; '
FROM TABLE
WHERE [limit number of rows]
SET @sSQL = @sSQL + 'COMMIT TRAN '
EXEC(@sSQL)
3.
how to use a WHILE LOOP in SQL Server (Transact-SQL)
DECLARE @site_value INT; SET @site_value = 0; WHILE @site_value <= 10 BEGIN PRINT 'Inside WHILE LOOP on TechOnTheNet.com'; SET @site_value = @site_value + 1; END; PRINT 'Done WHILE LOOP on TechOnTheNet.com'; GO
No comments:
Post a Comment