{"id":144,"date":"2019-09-30T22:06:25","date_gmt":"2019-09-30T19:06:25","guid":{"rendered":"http:\/\/www.potansif.com\/?p=144"},"modified":"2019-09-30T22:07:06","modified_gmt":"2019-09-30T19:07:06","slug":"sql-server-tablolar-icin-parametrik-sirali-alan-listesi","status":"publish","type":"post","link":"http:\/\/www.potansif.com\/?p=144","title":{"rendered":"SQL Server : Tablolar \u0130\u00e7in Parametrik S\u0131ral\u0131 Alan Listesi"},"content":{"rendered":"<p>\u0130leride kullan\u0131lmak \u00fczere elinizin alt\u0131nda bulunmas\u0131nda fayda oldu\u011funu d\u00fc\u015f\u00fcnd\u00fc\u011f\u00fcm bir tablo de\u011ferli fonksiyon \u00f6rne\u011fini payla\u015fmak istiyorum; Bu fonksiyon temelde ad\u0131n\u0131 verdi\u011finiz tablonun s\u00fctun yap\u0131s\u0131n\u0131 veri tablosu olarak vermeye yar\u0131yor;<br \/>\n<!--more--><br \/>\nBunu bir view olarak yapmak da m\u00fcmk\u00fcnd\u00fc fakat parametrik olmas\u0131 ve s\u0131ralama yap\u0131labilmesi gibi avantajlar\u0131 nedeniyle (Multi-Statement Table-Value) \u015feklinde kodlamak cazip geldi diyelim&#8230;<\/p>\n<pre><code>SET &nbsp;ANSI_NULLS &nbsp;ON\nGO\nSET &nbsp;QUOTED_IDENTIFIER &nbsp;ON\nGO\n-- &nbsp;=============================================\n-- &nbsp;Author &nbsp; &nbsp; &nbsp; : &lt;U\u011fur &nbsp;PARLAYAN&gt;\n-- &nbsp;Create &nbsp;date : &lt;2017-06-30-2158&gt;\n-- &nbsp;Description &nbsp;: &lt;Tablolar\u0131n s\u00fctun listesini ve bir ka\u00e7 yararl\u0131 bilgiyi i\u00e7erir&gt;\n-- &nbsp;=============================================\nALTER &nbsp;FUNCTION &nbsp;dbo.fnt_sys_Kolonlar( @TabloAdi VARCHAR(50) )\nRETURNS &nbsp;@SONUC TABLE\n( &nbsp;ID &nbsp; &nbsp; &nbsp; &nbsp;INT\n, &nbsp;Kolon &nbsp; &nbsp; VARCHAR(50)\n, &nbsp;VeriTipi &nbsp;VARCHAR(50)\n, &nbsp;CharSet &nbsp; VARCHAR(50)\n, &nbsp;Bayt &nbsp; &nbsp; &nbsp;INT\n, &nbsp;Bos &nbsp; &nbsp; &nbsp; BIT\n, &nbsp;Primal &nbsp; &nbsp;BIT\n) &nbsp;AS BEGIN\n&nbsp; &nbsp; INSERT INTO @SONUC (ID, Kolon, Primal, VeriTipi, Bos, Bayt, CharSet)\n&nbsp; &nbsp; SELECT &nbsp; &nbsp;\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;C.ORDINAL_POSITION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;as &nbsp;ID\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , &nbsp;C.COLUMN_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as &nbsp;Kolon\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , &nbsp;iif(T.CONSTRAINT_TYPE='PRIMARY KEY',1,0) &nbsp; &nbsp;as &nbsp;Primal\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , &nbsp;C.DATA_TYPE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as &nbsp;VeriTipi\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , &nbsp;iif(C.IS_NULLABLE='YES', &nbsp;1, &nbsp;0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;as &nbsp;Bos\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , &nbsp;COALESCE(C.CHARACTER_MAXIMUM_LENGTH, &nbsp;C.NUMERIC_PRECISION) &nbsp;as &nbsp;Bayt\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , &nbsp;C.CHARACTER_SET_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;as &nbsp;CharSet\n&nbsp; &nbsp; FROM &nbsp; &nbsp; INFORMATION_SCHEMA.COLUMNS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as &nbsp;C &nbsp;LEFT &nbsp;OUTER\n&nbsp; &nbsp; JOIN &nbsp; &nbsp; INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE as &nbsp;U &nbsp;ON &nbsp;U.TABLE_NAME = C.TABLE_NAME &nbsp;AND &nbsp;U.COLUMN_NAME = C.COLUMN_NAME &nbsp;LEFT &nbsp;OUTER\n&nbsp; &nbsp; JOIN &nbsp; &nbsp; INFORMATION_SCHEMA.TABLE_CONSTRAINTS &nbsp; &nbsp; &nbsp; as &nbsp;T &nbsp;ON &nbsp;T.TABLE_NAME = C.TABLE_NAME &nbsp;AND &nbsp;T.CONSTRAINT_NAME = U.CONSTRAINT_NAME\n&nbsp; &nbsp; WHERE &nbsp; &nbsp;C.TABLE_NAME = @TabloAdi\n&nbsp; &nbsp; ORDER BY C.ORDINAL_POSITION\n&nbsp; &nbsp; ;\n&nbsp; &nbsp; RETURN\nEND\nGO<\/code><\/pre>\n<p>Kullan\u0131m\u0131 ise olduk\u00e7a basit;<\/p>\n<pre><code>SELECT * FROM dbo.fnt_sys_Kolonlar('Cariler');<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0130leride kullan\u0131lmak \u00fczere elinizin alt\u0131nda bulunmas\u0131nda fayda oldu\u011funu d\u00fc\u015f\u00fcnd\u00fc\u011f\u00fcm bir tablo de\u011ferli fonksiyon \u00f6rne\u011fini payla\u015fmak istiyorum; Bu fonksiyon temelde ad\u0131n\u0131 verdi\u011finiz tablonun s\u00fctun yap\u0131s\u0131n\u0131 veri tablosu olarak vermeye yar\u0131yor<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-blog","tag-sql-server"],"_links":{"self":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=144"}],"version-history":[{"count":2,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":146,"href":"http:\/\/www.potansif.com\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions\/146"}],"wp:attachment":[{"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.potansif.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}