title: Regarding dynamic where clause
body: <p>This is my SQL:</p>
  
  <pre><code>DECLARE @tbl_WhereClause AS TABLE (
      SearchField VARCHAR(255),
      Operator VARCHAR(25),
      ConditionData VARCHAR(MAX),
      MatchCase BIT,
      TableName VARCHAR(MAX)   
  )
  
  DECLARE @WhereClause_XML XML
  SET @WhereClause_XML = 
  '&lt;NewDataSet&gt; 
    &lt;param&gt;
     &lt;SearchField&gt;EmployeeID&lt;/SearchField&gt;
     &lt;FilterCondition&gt; &gt;= &lt;/FilterCondition&gt;
     &lt;ConditionData&gt;201&lt;/ConditionData&gt;
     &lt;MatchCase&gt;0&lt;/MatchCase&gt;
     &lt;Table&gt;Employee&lt;/Table&gt;
   &lt;/param&gt;
   &lt;param&gt;  
     &lt;SearchField&gt;DeptID&lt;/SearchField&gt;
     &lt;FilterCondition&gt; = &lt;/FilterCondition&gt;
     &lt;ConditionData&gt;AC01&lt;/ConditionData&gt;
     &lt;MatchCase&gt;1&lt;/MatchCase&gt;
     &lt;Table&gt;Department&lt;/Table&gt;
   &lt;/param&gt;
   &lt;param&gt;  
     &lt;SearchField&gt;Dob&lt;/SearchField&gt;
     &lt;FilterCondition&gt; &gt;= &lt;/FilterCondition&gt;
     &lt;ConditionData&gt;20120104&lt;/ConditionData&gt;
     &lt;MatchCase&gt;0&lt;/MatchCase&gt;
     &lt;Table&gt;Employee&lt;/Table&gt;
   &lt;/param&gt;
  &lt;/NewDataSet&gt;'
  
  INSERT INTO @tbl_WhereClause (SearchField, Operator, ConditionData,  MatchCase,TableName)
  SELECT  A.B.value('(SearchField)[1]', 'VARCHAR(255)' ) SearchField,
      A.B.value('(FilterCondition)[1]', 'VARCHAR(25)' ) Operator,
      A.B.value('(ConditionData)[1]', 'VARCHAR(MAX)' ) ConditionData,
      A.B.value('(MatchCase)[1]', 'BIT' ) MatchCase,
      A.B.value('(Table)[1]', 'VARCHAR(MAX)' ) TableName
  FROM    @WhereClause_XML.nodes('/NewDataSet/param') A(B)
  
  SELECT * FROM @tbl_WhereClause
  </code></pre>
  
  <p>How can I join with the system table for each field to get the each field data type and show. please run the script and do the necessary changes in SQL. thanks</p>