27 Kasım 2017 Pazartesi

Sql Server T-Sql Notları



Sql query'leri tabify (formatlı) yapmak için:

http://www.dpriver.com/pp/sqlformat.htm



-String üzerinden hash üretme

HashBytes('MD5', [Sentence]) as hash  > varbinary to string ?
select cast(@b as varchar(max)) - olmadı
SELECT CONVERT(VARCHAR(1000), varbinary_value, 1);

-Sayfalama

FROM [TableX]
Order by Id --(mecburi)
  OFFSET (500000) ROWS FETCH NEXT (10000) ROWS ONLY
 
 

-String içerikte tümü büyük harf olanları bulma

select top 1000 * from [Table] 
where Text COLLATE Latin1_General_CS_AI = Upper(Text)
  
  

-Bir kelimenin text de kaç defa geçtiğini bulmak  

 SELECT CHARINDEX ( 'TEST',  
       'This is a Test'  
       COLLATE Latin1_General_CS_AS);
  
https://www.dbrnd.com/2016/02/sql-server-tsql-script-to-find-count-the-number-of-occurrences-of-a-string/
http://dataeducation.com/counting-occurrences-of-a-substring-within-a-string/

 

-ESCAPE 

WHERE LargePhotoFileName LIKE '%greena_%' ESCAPE 'a' ;  
Using WHERE with LIKE and ESCAPE syntax
and uses the ESCAPE option because is a wildcard character. Without specifying the ESCAPE option, the query would search for any description values that contain the word green followed by any single character other than the character.  


String Functions


https://docs.microsoft.com/en-us/sql/t-sql/functions/string-functions-transact-sql

Hiç yorum yok: