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 8618957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:13:39+00:00 2026-06-12T06:13:39+00:00

I was provided with an SQL query that outputs (PRINT) data neatly, the sticky

  • 0

I was provided with an SQL query that outputs (PRINT) data neatly, the sticky part is that I need to execute it (and use the output later obviously) through my application which already makes use of EF4.1.

Here’s what I have so far.

        string sqlQuery = string.Empty;
        _ctx.Connection.Open();
        DbCommand com = _ctx.Connection.CreateCommand();

        sqlQuery = @"declare @note varchar(1000)
                    set @note = (select
                    'Client: '+cast([NO_CLIENT] as varchar)+' - '+TABLE1.[nom]+
                    CHAR(13)+CHAR(10)+
                    'Adr_1 '+[ADR_1]+
                    CHAR(13)+CHAR(10)+
                    'Adr_2 '+[ADR_2]+
                    CHAR(13)+CHAR(10)+
                    'Adr_3 '+[ADR_3]+
                    CHAR(13)+CHAR(10)+
                    'Adr_4 '+[ADR_4]+
                    CHAR(13)+CHAR(10)+
                    'Contact: '+[CONTACT]+
                    CHAR(13)+CHAR(10)+
                    'Postal Code|Code Postal: '+substring([CODE_POSTAL],1,3)+' '+substring([CODE_POSTAL],4,3)+
                    CHAR(13)+CHAR(10)+
                    'Tel No: '+[TELEPHONE]+' Ext.: '+[POSTE_EXTENSION]+
                    CHAR(13)+CHAR(10)+
                    'Fax No: '+[NO_FAX]+
                    CHAR(13)+CHAR(10)+
                    'Clinic: '+[CLINIQUE_QUI_FACTURE]+
                    CHAR(13)+CHAR(10)+
                    'Langu.: '+ case [LANGUE] when 1 then 'Fr' when 2 then 'En' Else 'N/A'  end+
                    CHAR(13)+CHAR(10)+
                    case [ACTIF] when 0 then 'Non-Active|Inactif' when 1 then 'Active|Actif' Else 'N/A' end+
                    CHAR(13)+CHAR(10)+
                    'Account Man.|Chargé Cpte: '+CAST(TABLE1.[NO_VENDEUR_1] AS VARCHAR)+' - '+clve.[NOM]+
                    CHAR(13)+CHAR(10)+
                    'DATE REGISTERED|DATE ENREGISTREMENT: '+[DATE_ENREGISTREMENT]+
                    CHAR(13)+CHAR(10)+
                    '---------- MARKETING INFO ----------'+
                    CHAR(13)+CHAR(10)+
                    'Company|Cie: '+[TABLE2_NOM]+
                    CHAR(13)+CHAR(10)+
                    'Contact: '+[TABLE2_CONTACT]+
                    CHAR(13)+CHAR(10)+
                    'Tel.: '+[TABLE2_TELEPHONE]+
                    CHAR(13)+CHAR(10)+
                    'Adr_1: '+[TABLE2_ADR1]+
                   CHAR(13)+CHAR(10)+
                   'Adr_2: '+[TABLE2_ADR2]+
                   CHAR(13)+CHAR(10)+
                   'Adr_3: '+[TABLE2_ADR3]+
                   CHAR(13)+CHAR(10)+
                   'Adr-4: '+[TABLE2_ADR4]+
                   CHAR(13)+CHAR(10)+
                   'City|Ville: '+[TABLE2_VILLE_PROV]+
                   CHAR(13)+CHAR(10)+
                   'Postal Code|Code Postal: '+substring([TABLE2_CODE_POSTAL],1,3)+' '+substring([TABLE2_CODE_POSTAL],4,3)+
                   CHAR(13)+CHAR(10)+
                   'Fax No: '+[TABLE2_FAX_1]+
                   CHAR(13)+CHAR(10)+
                   'Ext.: '+[TABLE2_FAX_1_POSTE]+
                   CHAR(13)+CHAR(10)+
                   'Fax 2 :'+[TABLE2_FAX_2]+
                   CHAR(13)+CHAR(10)+
                   'Email1: '+[TABLE2_EMAIL1]+
                   CHAR(13)+CHAR(10)+
                   'Email2: '+[TABLE2_EMAIL2]

                    FROM TABLE1 
                        left join TABLE3 on TABLE1.no_vendeur_1 = TABLE3.no_vendeur
                        where [NO_CLIENT] = 2003)


                    print @note

                ";

        com.CommandText = @sqlQuery;
        DbDataReader rd = com.ExecuteReader();

The query executes fine in SQL Management Studio, but I get this exception when the application runs it: (looks like it is parsing it somehow)

The query syntax is not valid. Near term '@note', line 1, column 14.

What do you think am I doing wrong ? (Probably everything lol)

  • 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-12T06:13:40+00:00Added an answer on June 12, 2026 at 6:13 am

    Here’s what I ended up doing:

    var r = _ctx.ExecuteStoreQuery<string>(@sqlQuery).FirstOrDefault();
    

    The sqlQuery declares and sets value for @note, then select‘s it in the end.

    r will contain flat text.

    This has pointed me in the right direction: ExecuteStoreCommand returns -1 , EntityFramework , C#?

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

Sidebar

Related Questions

I have a query result set that contains data that I need to filter,
I've got a query (for use in bug tracker.net) that calculates the number of
I have a SQL query that I'm currently solving by doing two queries. I
I'm trying to write a linq-to-sql query using || that behaves the same way
Im trying to write an SQL query that will check in the table ‘persons’
I needed to come up with a SQL query that returns rows that satisfy
I have a query that runs super fast when executed in the sql editor
I'm attempting to migrate a database with a SQL file I was provided. However,
SQL Server provides the type [rowguid]. I like to use this as unique primary
I'm using the ASP.NET SQL Membership Provider. So, there's an aspnet_Users table that has

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.