title: Cast sql_variant into data_type provided as varchar
body: <p>I have a following sql table:</p>
  
  <pre><code> Types table
  
      --------------------------------------
      |Name(varchar(50))|Type (varchar(50))|
      --------------------------------------
      | Car             | varchar(50)      |
      | Apples          | int              |
      --------------------------------------
  </code></pre>
  
  <p>I am using another tables for storing values such as:</p>
  
  <pre><code>Apples table:
  
      ----------------------------
      |Value (providedType - int)|
      ----------------------------
      |50                        |
      |60                        |
      ----------------------------
  </code></pre>
  
  <p>To insert values into these tables I am using a stored procedure (part of it):</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[AddValue]
  @value sql_variant
  @name varchar(50)
  @tableName (50)
  AS
  BEGIN
  
  DECLARE @Sql NVARCHAR(MAX)
  DECLARE @valueType VARCHAR(50)
  SET @valueType = (SELECT [Type] FROM [dbo].[Types] WHERE [Name] = @name)
  
  SET @Sql = N'INSERT INTO [dbo].'+ @tableName + N' VALUES(' + @value + N')'
  EXECUTE sp_executesql @Sql 
  ...
  </code></pre>
  
  <p>Dynamic execute will throw an exception that implicit casting of sql_variant is not allowed. Is there any way to convert sql_variant type into the type that is provided as varchar? 
  Such as:</p>
  
  <pre><code>CONVERT(@valueType, @value)
  </code></pre>
  
  <p>Where @valueType is varchar not datetype </p>