Non ho mai lavorato con le funzioni del database, ma il mio progetto attuale lo richiede. Devo inserire una query sql comune in una funzione in modo da non doverla digitare nel nostro codice centinaia di volte. Ho creato la funzione, ma non so come usarla.Come si verifica una funzione con valori di tabella in SQL Server Management Studio?
Ecco il codice funzione:
USE [DB_NAME] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[fn_GetConfigurationByProfile] ( @profileName AS NVARCHAR(50) ) RETURNS TABLE AS RETURN ( -- Fill the table variable with the rows for your result set SELECT system_settings_groups.ssg_id, system_settings_groups.ssg_name, system_settings_groups.ssg_parent_group_id, system_settings_names.ssn_name, system_Settings_names.ssn_display_name, system_settings_values.ssv_value FROM system_settings_profiles JOIN system_settings_values ON system_settings_profiles.ssp_id = system_settings_values.ssv_ssp_id JOIN system_settings_names ON system_settings_names.ssn_id = system_settings_values.ssv_ssn_id JOIN system_settings_groups ON system_settings_groups.ssg_id = system_settings_names.ssn_ssg_id WHERE system_settings_profiles.ssp_name = @profileName )
Così come dovrei utilizzare questo in una query SQL? Utilizzo semplicemente SELECT fn_GetConfigurationByProfile ('DEFAULTPROFILE')?
Questa potrebbe essere una domanda amatoriale, ma vabbè. Ho bisogno di aiuto :)
Grazie per la risposta tempestiva. Mi sento come un noob totale di non avere però questo dato che era una funzione valutata a livello di tabella:/ – Jeff
leggi come mi è stato dato.hope che ti aiuterà di più :) – anishMarokey