String Declaration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Heavey

    String Declaration

    I have an SQL statement which is quite long. I want to declare a string
    variable with this SQL statement and I want to have span multiple lines. I
    could scrunch it all up and place it on a single line, but then the SQL
    statement would be unreadable. There was a way to do this in VB, but how do
    you do this is C#?

    I want it to look something like this in the code.

    string mySQL = "select 'Anchor' as Anchor_NonAncho r, combo.PROCESS_G ROUP,
    combo.COMBINATI ON, cf.CHARTFIELD,
    grp.COMBO_DEFN_ NAME, ' ' as Tree_Name, ' ' as
    Node_Name,
    cf.SEQUENCE_NBR _6, cval.SELECT_VAL UE as Range_From,
    ' ' as
    Range_To
    from gapsc.ps_combo_ grrul_tbl combo,
    gapsc.ps_combo_ rule_tbl Rul,
    gapsc.ps_combo_ group_tbl grp,
    gapsc.ps_combo_ cf_tbl cf,
    gapsc.ps_combo_ val_tbl cval
    where Rul.EFFDT_TO = '2099-01-01'
    and rul.combination = combo.combinati on
    and grp.setid = rul.setid
    and combo.setid = cf.setid
    and rul.combination = cf.combination
    and rul.combination = cval.combinatio n
    and grp.Process_Gro up = combo.Process_G roup
    and grp.combo_defn_ name = rul.combo_Defn_ Name
    and cf.SETID = cval.SETID
    and cf.COMBINATION = cval.COMBINATIO N
    and cf.SEQUENCE_NBR _6 = cval.SEQUENCE_N BR_6
    and cf.TREE_NAME = ' ' ";

    Thanks in advance!!
  • Marc Gravell

    #2
    Re: String Declaration

    string mySQL = @"Some long
    text with "" double quote escapting of single quotes
    that goes on and on and on";

    Or use an sp (or the equivalent name for your database) ;-p

    (oh don't look at me like that... someone was bound to say it!)

    Marc


    Comment

    • Chris Dunaway

      #3
      Re: String Declaration

      Marc Gravell wrote:
      string mySQL = @"Some long
      text with "" double quote escapting of single quotes
      that goes on and on and on";
      >
      Or use an sp (or the equivalent name for your database) ;-p
      >
      (oh don't look at me like that... someone was bound to say it!)
      >
      Marc
      Just for completeness, you can also continue your string onto the next
      line:

      string mySQL = "SELECT field1, field2 " +
      " FROM table " +
      "WHERE Id = @Id";

      Comment

      Working...