Showing posts with label T-SQL. Show all posts
Showing posts with label T-SQL. Show all posts
Check if a temp table exists (TSQL)
if object_id('##temp_table') is null print 'DOES NOT EXIST' else print 'EXISTS'
Generate row ID (T-SQL)
Let's assume we have all our data in a table MyTable, with a column named MyTableID, that we want to fill with unique consecutive values.
DECLARE @Index BIGINT
SET @Index = 0
UPDATE MyTable
SET @Index = MyTableID = @Index + 1
How to declare a function (T-SQL)
CREATE FUNCTION MyFunction
(
@EntryParam BIGINT
)
RETURNS BIGINT --the returned type
AS
BEGIN
DECLARE @ReturnVar AS BIGINT -- the var to keep the return value
..... -- set @ReturnVar's value
RETURN @ReturnVar
END
Subscribe to:
Posts (Atom)