SQL conditional SELECT -


I would like to create a stored procedure with parameters that indicate which field should be selected.

I would like to pass two parameters "selectField1" and "selectField2" each as bools.

I want something

  SELECT if (selectField1 = true) field 1 Do not select ELSE field 1 (selectField2 = true) Field 2 of field 2 from ELSE table   

Want the ability to return the areas with permission, which means that the number of returning areas should also be dynamic. It will work with 2 variables. More than anything else will be confused. Choose Selection (selectfield1 = true and selectField2 = true) Select field 1, from field 2 to the table end (selectField1 = true) Start Select from Table 1 Field 1 Select first (selectField2 = true) SELECT field from end field 2 < / Code>

This example will help with dynamic SQL multiples is true, at least 1 column is assuming.

  announcement @ sql varchar (MAX) SET @sql = 'select' IF (selectField1 = true) BEGIN SET @sql = @sql + 'field 1,' end if (selectField2 = true) BEGIN SET @sql = @sql + 'field2,' end ... - DROP ',' @sql = SUBSTRING (@ SQL, 1, LAN (SSLL-2) SET @ SQL = @ SQL + 'FARM table' EXEC (@sql)  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -