Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8099481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:25:15+00:00 2026-06-05T22:25:15+00:00

I have a table, in one of the fields I stored a string like

  • 0

I have a table, in one of the fields I stored a string like this:

RMaster.dbo.fnFormatDate (GETUTCDATE(), 'Company_Enroll_YYYY-MM-DD.csv')

I would like to use it as part of the query that I could call from my c# code, so the query would look like this:

Select ThisField, …
From mytable

Is this doable?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:25:17+00:00Added an answer on June 5, 2026 at 10:25 pm

    Yes, just generate a SQL string by nesting.

    SET NOCOUNT ON;
    DECLARE @t TABLE (formula NVARCHAR(MAX));
    INSERT @t(formula) SELECT 
      'RMaster.dbo.fnFormatDate (GETUTCDATE(), ''Company_Enroll_YYYY-MM-DD.csv'')';
    
    DECLARE @sql NVARCHAR(MAX);
    
    SELECT @sql = N'SELECT ' + formula + ', [other columns] 
      FROM dbo.mytable' FROM @t -- WHERE...;
    
    PRINT @sql;
    --EXEC sp_executesql @sql;
    

    EDIT

    Here is one way to handle the multi-row scenario:

    SET NOCOUNT ON;
    
    CREATE TABLE dbo.src(ID INT, formula NVARCHAR(MAX));
    INSERT dbo.src(ID, formula) SELECT 
      1, 'RMaster.dbo.fnFormatDate (GETUTCDATE(), ''Company_Enroll_YYYY-MM-DD.csv'')'
      UNION ALL SELECT 
      2, 'RMaster.dbo.fnFormatDate (GETUTCDATE(), 'Foo_MM.DD.YYYY.csv'')';
    
    DECLARE @sql NVARCHAR(MAX);
    SET @sql = N'';
    
    SELECT @sql = @sql + CHAR(13) + CHAR(10) + N'UNION ALL SELECT ID, ' + formula + '
      FROM dbo.src WHERE ID = ' + CONVERT(VARCHAR(12), ID)
      FROM dbo.src -- WHERE...;
    
    SET @sql = STUFF(@sql, 1, 12, '') + ';';
    
    PRINT @sql;
    --EXEC sp_executesql @sql;
    
    DROP TABLE dbo.src;
    

    This produces an ugly union query:

    SELECT ID, RMaster.dbo.fnFormatDate (GETUTCDATE(), 'Company_Enroll_YYYY-MM-DD.csv')
      FROM dbo.src WHERE ID = 1
    UNION ALL SELECT ID, RMaster.dbo.fnFormatDate (GETUTCDATE(), 'Foo_MM.DD.YYYY.csv')
      FROM dbo.src WHERE ID = 2;
    

    You could probably build an awful and much more complicated CASE expression dynamically, but as long as there’s a good supporting index on ID so that each query is a single-row seek, this should be okay. The calls to the UDF are probably going to kill you more than the rest of the query anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a favorite table containing some fields like login_id,driver_id(One login_id may have many
I have one table that has two fields - ID1 and ID2 ID1 can
I have a table in database that is having some fields one of which
I have one table, t1, which has fileds called userid, week and year fields.
I have a table in a django app where one of the fields is
I have a categories table, which one of the fields serves as the foreign
I have a DB with many tables and one of the table has fields:
I have a stored procedure which returns all the fields of a table plus
I have a table in which in one of the column I would be
I have one table view that should be filtered by values of search field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.