Monday, June 29, 2015
Thursday, June 18, 2015
SQL nested case when then
CASE
WHEN alertcon.alert_type = 'E'
THEN
CASE
WHEN alertgat.gateway_id = 'M' THEN escUser.login_id
WHEN alertgat.gateway_id = 'E' THEN escUser.email_id
ELSE ''
END
WHEN alertcon.alert_type = 'R'
THEN
CASE
WHEN alertgat.gateway_id = 'M' THEN escUser.login_id
WHEN alertgat.gateway_id = 'E' THEN escUser.email_id
ELSE ''
END
END as Recepient
WHEN alertcon.alert_type = 'E'
THEN
CASE
WHEN alertgat.gateway_id = 'M' THEN escUser.login_id
WHEN alertgat.gateway_id = 'E' THEN escUser.email_id
ELSE ''
END
WHEN alertcon.alert_type = 'R'
THEN
CASE
WHEN alertgat.gateway_id = 'M' THEN escUser.login_id
WHEN alertgat.gateway_id = 'E' THEN escUser.email_id
ELSE ''
END
END as Recepient
Tuesday, June 16, 2015
Monday, June 15, 2015
Static Cursors
A static cursor populates the result set at the time of cursor creation and query result is cached for the lifetime of the cursor. A static cursor can move forward and backward direction. A static cursor is slower and use more memory in comparison to other cursor. Hence you should use it only if scrolling is required and other types of cursors are not suitable.
No UPDATE, INSERT, or DELETE operations are reflected in a static cursor (unless the cursor is closed and reopened). By default static cursors are scrollable. SQL Server static cursors are always read-only.
- SET NOCOUNT ON
- DECLARE @Id int
- DECLARE @name varchar(50)
- DECLARE @salary int
- DECLARE cur_emp CURSOR
- STATIC FOR
- SELECT EmpID,EmpName,Salary from Employee
- OPEN cur_emp
- IF @@CURSOR_ROWS > 0
- BEGIN
- FETCH NEXT FROM cur_emp INTO @Id,@name,@salary
- WHILE @@Fetch_status = 0
- BEGIN
- PRINT 'ID : '+ convert(varchar(20),@Id)+', Name : '+@name+ ', Salary : '+convert(varchar(20),@salary)
- FETCH NEXT FROM cur_emp INTO @Id,@name,@salary
- END
- END
- CLOSE cur_emp
- DEALLOCATE cur_emp
- SET NOCOUNT OFF
Printing Time variable and string on same line in SQL
print 'There are ' + CAST(@OfficeStartTime AS VARCHAR) + ' alias combinations did not match a record'
SQL case when then else
CASE WHEN ebv.db_no IN (22978,23218,23219) THEN 'WECS 9500' ELSE 'WECS 9520' END
Subscribe to:
Posts (Atom)