-1

I am new to SQL and i created a query has which has to display a table with many filtering. so I created Query like this one;

*-- input--
select CountryID, COUNT([Document name]) as inputcount ,
MONTH([Creation Date]) AS [Creation Month],Year([Creation Date]) as [Creation Year] INTO TEMP
from dbo.ggg` `
WHERE  [doc_type_product_type] not in ('CUST')
and [Document_Source] in ('FAX','Original') 
AND ([Monto en Dolares test]  > 0 or [Monto en Dolares test]  = null) 
group by [CountryID],MONTH([Creation Date]) ,Year([Creation Date]) order by [CountryID];*

And every this is fine with this query, but in case new filters show up then i don't have to make alteration to this query or script. So i think there is a way where i can store the filters and pass them to my query and in case of alteration or update i can do it on the table. Any suggestions.

McGrady
  • 10,869
  • 13
  • 47
  • 69
issam ozeir
  • 23
  • 1
  • 4
  • 6
    My 1st suggestion is to stop using all caps when writing your question. – takendarkk Aug 01 '17 at 15:40
  • What is the question here? It is like reading a stream of consciousness. There is nothing coherent in the question at all. What are you actually asking here?? – Sean Lange Aug 01 '17 at 15:44
  • Paremeterized query? https://stackoverflow.com/questions/4407070/how-to-write-a-parametrized-query-in-management-studio or https://www.mssqltips.com/sqlservertip/2981/using-parameters-for-sql-server-queries-and-stored-procedures/? – xQbert Aug 01 '17 at 15:46
  • 1
    The solution you are looking for is called a [VIEW](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql) – Bartosz X Aug 01 '17 at 15:47
  • Hello my question is in case i have new filter in the [Document_Source] Field how this new filter to the existing query , without making alteration to the query it self since i have a lot of queries. so the question is there should be way where i can store my filters in one place or table and then i can pass these filters to the existing queries? --Thank you – issam ozeir Aug 01 '17 at 16:18

1 Answers1

0

I think Bartosz X is correct, the easiest way to maintain (new/old) filters is to probably build a view and use the 'Filter' column in design. That way you do not have to directly edit the query.

enter image description here

Hope this helps!

Simon
  • 1,201
  • 9
  • 18