SQL – CTE vs VIEW

Views can be indexed but CTE can’t. So this is one important point. CTE work excellent on tree hierarchyi.e. recursive Also, consider views when dealing with complex queries. Views being a physical object on database (but does not store data physically) and can be used on multiple queries, thus provide flexibility and centralized approach. CTE, … Read more

Loop through all the rows of a temp table and call a stored procedure for each row

you could use a cursor: DECLARE @id int DECLARE @pass varchar(100) DECLARE cur CURSOR FOR SELECT Id, Password FROM @temp OPEN cur FETCH NEXT FROM cur INTO @id, @pass WHILE @@FETCH_STATUS = 0 BEGIN EXEC mysp @id, @pass … — call your sp here FETCH NEXT FROM cur INTO @id, @pass END CLOSE cur DEALLOCATE … Read more

Comma separated list in SQL

declare @S varchar(20) set @S = ‘1,2,3,4,5’ while len(@S) > 0 begin –print left(@S, charindex(‘,’, @S+’,’)-1) exec YourSP left(@S, charindex(‘,’, @S+’,’)-1) set @S = stuff(@S, 1, charindex(‘,’, @S+’,’), ”) end Try on SE Data: Walk the string

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)