INDEXING CREATE & PERMISSION FOR USER

https://www.techonthenet.com/sql_server/indexes.php


ALTER procedure [dbo].[AddNumberFromString]
as
begin
DECLARE @string varchar(100)
Declare @addstr int
SET @string = 'ma46h1es2hgggggg5'
set @addstr=0

WHILE PATINDEX('%[^0-9]%',@string) <> 0
SET @string = STUFF(@string,PATINDEX('%[^0-9]%',@string),1,'')

declare @count int
set @count=1

while(@count<=len(@string))
begin
set @addstr=(SUBSTRING(@string,@count,1))+@addstr

set @count=@count+1

end
select @addstr as total
end


-------Missing Number---------------------------

SELECT ID2, Name2, City2, PinCode2 FROM [dbo].[tbl2]

DECLARE @tempdata AS TABLE
(
 ID INT
)

DECLARE @MaxID INT = 0, @Counter INT = 1
SELECT @MaxID = MAX(ID2) FROM [dbo].[tbl2]

WHILE (@Counter < @MaxID)
 BEGIN
  INSERT INTO @tempdata VALUES (@Counter)
  SET @Counter = @Counter + 1
 END

SELECT ID FROM @tempdata AS T
LEFT JOIN [dbo].[tbl2] AS T2 ON (T2.ID2 = T.ID)
WHERE T2.ID2 IS NULL

------oooooooooooooooo------------------------------------
DECLARE @exclude varchar(50)
    SET @exclude = '0:;<=>?@O[]`^\/'
    DECLARE @char char
    DECLARE @len char
    DECLARE @output varchar(50)
    set @output = ''
    set @len = 8

    while @len > 0 begin
       select @char = char(round(rand() * 74 + 48, 0))
       if charindex(@char, @exclude) = 0 begin
           set @output = @output + @char
           set @len = @len - 1
       end
    end

   SELECT @output

Comments

Popular posts from this blog

Filegroups - Creating a new file group and making it the default

Complex Queries !

How to Use the Telnet Client in Windows