Tag: funkcje

Development, SQL Server

Prosta konkatenacja napisów w wierszach według ustalonej kolejności (2017+)

 STRING_AGG()   to długo wyczekiwana funkcja. Konkurencja miała już ją od dawna. A my musieliśmy kombinować i stawiać protezy (recursive cte, xml, clr, meh..) SQL Server 2017 (i Azure) nam wreszcie ją udostępnia. Warto jednak pamiętać, że domyślnie napisy złączane są według kolejności losowej (takiej, z jaką „wpadną w ręce” silnika),Czytaj dalej / Read more

Development, SQL Server

Zaawansowane przesuwanie okien :D (czyli użycie funkcji „okienkowych” OVER i zastosowanie ROWS,RANGE,BETWEEN,UNBOUNDED, CURRENT, PRECEDING, FOLLOWING)

Z dokumentacji technet: https://msdn.microsoft.com/pl-pl/library/ms189461%28v=sql.110%29.aspx ROWS | RANGE Further limits the rows within the partition by specifying start and end points within the partition. This is done by specifying a range of rows with respect to the current row either by logical association or physical association. Physical association is achieved byCzytaj dalej / Read more

Development, SQL Server

Potęga funkcji okna – SELECT LAG(), LEAD(), FIRST_VALUE(), LAST_VALUE()

Z dokumentacji technet: https://msdn.microsoft.com/en-us/library/hh231256.aspx https://msdn.microsoft.com/en-us/library/hh213125.aspx https://msdn.microsoft.com/en-us/library/hh213018.aspx https://msdn.microsoft.com/en-us/library/hh231517.aspx LAG provides access to a row at a given physical offset that comes before the current row. LEAD provides access to a row at a given physical offset that follows the current row. FIRST_VALUE returns the first value in an ordered set ofCzytaj dalej / Read more

Development, SQL Server

fn_my_permissions() – Sprawdzenie jakie mamy uprawnienia do bazy danych

Z dokumentacji technet ( http://msdn.microsoft.com/en-us/library/ms176097%28v=sql.105%29.aspx ) Returns a list of the permissions effectively granted to the principal on a securable. Przy pomocy tego polecenia możemy w szybki sposób sprawdzić nasze uprawnia względem konkretnego obiektu. Obiektem może być serwer, baza i oczywiście wszystkie inne, do których dostęp zarządzany jest przez uprawnienia sqlCzytaj dalej / Read more

Development, SQL Server

SELECT {fn TRUNCATE( 100.123456, 4)};

Z dokumentacji technet ( http://msdn.microsoft.com/en-us/library/bb630290(v=sql.105).aspx ) „You can use ODBC Scalar Functions in Transact-SQL statements. These statements are interpreted by SQL Server. They can be used in stored procedures and user-defined functions. These include string, numeric, time, date, interval, and system functions.” Dzisiaj coś mniej praktycznego, ale za to ciekawie wyglądającegoCzytaj dalej / Read more