Posts

Showing posts with the label SQL

Days, Hour, Minute & Second inSql Like Facebook notification

DECLARE @TotalSec int DECLARE @DiffSecs int SET @TotalSec = 24*60*60 SELECT       --DATEDIFF(SECOND, Created_Date, getdate()), CASE   WHEN CONVERT(char(2), (DATEDIFF(SECOND, Created_Date, getdate())/@TotalSec)) > 0 THEN   CAST(CONVERT(char(2), (DATEDIFF(SECOND, Created_Date, getdate())/@TotalSec))AS VARCHAR)+' Day'+' ' + CAST(CONVERT(char(2), ((DATEDIFF(SECOND, Created_Date, getdate())%@TotalSec)/3600))AS VARCHAR)+' Hr'    WHEN CONVERT(char(2), ((DATEDIFF(SECOND, Created_Date, getdate())%@TotalSec)/3600)) > 0 And CONVERT(char(2), (DATEDIFF(SECOND, Created_Date, getdate())/@TotalSec)) <= 0 THEN     CAST(CONVERT(char(2), ((DATEDIFF(SECOND, Created_Date, getdate())%@TotalSec)/3600))AS VARCHAR)+' Hr' +' ' +CAST(CONVERT(char(2), (((DATEDIFF(SECOND, Created_Date, getdate())%@TotalSec)%3600)/60))AS VARCHAR)+' min' WHEN CONVERT(char(2), (((DATEDIFF(SECOND, Created_Date, getdate())%@TotalSec)%3600)/60)) ...

SQL Server - Invalid Use of a Side-Effecting Operator 'insert' within a Function

Introduction : Here I will explain how to solve the problem of “ invalid use of a side-effecting operator 'insert' within a function in SQL Server ”. Description : In previous posts I explained many articles relating to solve errors in asp.net , SQL Server , IIS , etc. Now I will explain how to solve the problem of “ invalid use of a side-effecting operator 'insert' within a function in SQL Server ”. Generally this problem will occur whenever we try to write insert, update and delete queries inside of SQL Server functions like as shown below CREATE FUNCTION [dbo] . [testfunction] ( @LeadChannel VARCHAR ( 250 ), @UserId INT ) RETURNS INT AS BEGIN DECLARE @Channel INT Set @Channel  = 0 INSERT INTO PRESALE_LeadChannel (Source, Createdby ) VALUES ( @LeadChannel , @UserId ) SELECT @Channel = @@IDENTITY RETURN @Channel END In above function I written insert query because of that when we call ...

SQL Server Get List of Stored Procedures Where a Table Name is Used

Introduction : Here I will explain SQL Server query to get a list of stored procedures where table is used or SQL query to get list of procedures which contains table name in SQL Server . Description: In previous posts I explained can function return multiple values in SQL Server , Difference between view & stored procedure in SQL , update multiple tables using inner join in SQL Server many articles relating to SQL Server , asp.net , IIS , etc. Now I will explain how to get list procedures which contains particular table in SQL Server .   If we want to get list procedures which contains particular table name we need to write the query like as shown below SELECT Name FROM sys . procedures WHERE OBJECT_DEFINITION ( OBJECT_ID ) LIKE '%YourTableName%' Example Query SELECT Name FROM sys . procedures WHERE OBJECT_DEFINITION ( OBJECT_ID ) LIKE '%UserInformation%' Once we run above query we will get o...