I want to find header row dynamically and create table schema with that header.

  • DBA.k

    Ten Centuries

    Points: 1085

    CREATE TABLE [dbo].[NewTable1](

    [18/10/2020 date] [nvarchar](255) NULL

    ) ON [PRIMARY]

    GO

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'This is test file')

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (NULL)

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'20-20-2020')

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (NULL)

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'ID,name,sal')

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'10,mahi,2000')

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'20,ravi,1000')

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'30,ram,3000')

    INSERT [dbo].[NewTable1] ([18/10/2020 date]) VALUES (N'total emp:3')

    As per above script data will store in a single column with cama separate or any other delimiter which is semicolon ; etc.. so first i need to find out in which row header will be there and based on header (ID,name,sal') i need to create table schema dynamically.. so may be in another table i have more columns that has to automatically create table with that header..

    Kindly help on this ....

     

    • This topic was modified 2 months, 2 weeks ago by  DBA.k.
    • This topic was modified 2 months, 2 weeks ago by  DBA.k.
  • Phil Parkin

    SSC Guru

    Points: 244598

    Why have you started a new thread about this?

    Original thread here includes as-yet unanswered questions for the OP.

    If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.
    See https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help/ for details of how to post T-SQL code-related questions.

  • DBA.k

    Ten Centuries

    Points: 1085

    Thank you.. I am sorry But that unanswered question is regarding SSIS process from txt file.. This having next task which is data will be in Sql server table.. From that need to find header and create table.. I am sorry now  i have unsubscribe the old one..

    • This reply was modified 2 months, 2 weeks ago by  DBA.k.
  • DBA.k

    Ten Centuries

    Points: 1085

    can you please help on this task

  • Jeff Moden

    SSC Guru

    Points: 996676

    DBA.k wrote:

    can you please help on this task

    Yes but let's stop this thread and take it back to the original thread where I see you've provided the information I asked for.  I can't help right this instant because I'm working but will have a go of it tonight.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".
    "If "pre-optimization" is the root of all evil, then what does the resulting no optimization lead to?"

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply