Skip to content Skip to sidebar Skip to footer

Sql Server Continue Long String on Next Line

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Continue line of code on next line

2

  • Forum
  • Search
  • FAQs
  • Links
  • MVPs

Continue line of code on next line

Continue line of code on next line

(OP)

HI

I have a long line of code which is so long is dropping onto the next line in the module. The code is an SQL query and so needs to be in a continuous line (as far as I know) so that the coding works otherwise it treats it as another line of coding. Is there any way I can tell access that this is all one line of code and to continue treating it as such even though it is split across 2 lines?

Any advise is greatly appreciated.

Many Thanks

Tim

RE: Continue line of code on next line

2

RE: Continue line of code on next line

(OP)

can't get access to accept that, maybe you could show me what you mean if I give you my bit of code:

StrSql1 = "SELECT DISTINCT [Holiday/Sickness_cover].Intance,WeekLog.[Employee Number]as emp1,[Holiday/Sickness_cover].[Hol/sick_shift], [Holiday/Sickness_cover].Cover_Shift, TeamMembers.Employee as emp2, TeamMembers.Active, TeamMembers.Coverflag FROM ((([Holiday/Sickness_cover] INNER JOIN (Shift_Patterns INNER JOIN WeekLog ON (Shift_Patterns.ShiftLevel = WeekLog.ShiftLevel) AND (Shift_Patterns.[ShiftPattern ID] = WeekLog.[ShiftPattern ID])) ON [Holiday/Sickness_cover].[Hol/sick_shift] = Shift_Patterns.unique) INNER JOIN Shift_Patterns AS Shift_Patterns_1 ON [Holiday/Sickness_cover].Cover_Shift = Shift_Patterns_1.unique) INNER JOIN WeekLog AS WeekLog_1 ON (Shift_Patterns_1.[ShiftPattern ID] = WeekLog_1.[ShiftPattern ID]) AND (Shift_Patterns_1.ShiftLevel = WeekLog_1.ShiftLevel))"
INNER JOIN TeamMembers ON WeekLog_1.[Employee Number] = TeamMembers.Employee WHERE (((WeekLog.[Employee Number])=" & rst.Fields("emp") & ") And((TeamMembers.Active)=Yes)And((TeamMembers.Coverflag)Is Null))ORDER BY[Holiday/Sickness_cover].Intance;"

RE: Continue line of code on next line

Take each line, make sure that there is a space before the
closing quote and then add & _
Then start the next line with the opening quotes.

Try that.

David Pimental
(US, Oh)
dpimental@checkfree.com

RE: Continue line of code on next line

(OP)

I figured it out now I had to put & _ and then it worked like this

StrSql1 = "SELECT DISTINCT [Holiday/Sickness_cover].Intance,WeekLog.[Employee Number]as emp1,[Holiday/Sickness_cover].[Hol/sick_shift], [Holiday/Sickness_cover].Cover_Shift, TeamMembers.Employee as emp2, TeamMembers.Active, TeamMembers.Coverflag FROM ((([Holiday/Sickness_cover] INNER JOIN (Shift_Patterns INNER JOIN WeekLog ON (Shift_Patterns.ShiftLevel = WeekLog.ShiftLevel) AND (Shift_Patterns.[ShiftPattern ID] = WeekLog.[ShiftPattern ID])) ON [Holiday/Sickness_cover].[Hol/sick_shift] = Shift_Patterns.unique) INNER JOIN Shift_Patterns AS Shift_Patterns_1 ON [Holiday/Sickness_cover].Cover_Shift = Shift_Patterns_1.unique) INNER JOIN WeekLog AS WeekLog_1 ON (Shift_Patterns_1.[ShiftPattern ID] = WeekLog_1.[ShiftPattern ID]) AND (Shift_Patterns_1.ShiftLevel = WeekLog_1.ShiftLevel)) " & _

"INNER JOIN TeamMembers ON WeekLog_1.[Employee Number] = TeamMembers.Employee WHERE (((WeekLog.[Employee Number])=" & rst.Fields("emp") & ") And((TeamMembers.Active)=Yes)And((TeamMembers.Coverflag)Is Null))ORDER BY[Holiday/Sickness_cover].Intance;"

Cheers for the help and pointing in the right direction.

Tim

RE: Continue line of code on next line

(OP)

You replied the same time as me. funny! Im gonna give you a star though cus it was great help

tim

RE: Continue line of code on next line

RE: Continue line of code on next line

Nice A-Team reference.

I always put the & at the start of the next line, so it's clear to me that it's a continuation of the line above it. Access knows no matter where it is, but that allows me to read it more easily. Just a personal preference.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See Thread181-473997 for more pointers.

RE: Continue line of code on next line

What I would have done is create a String variable called strSQL.  Next, I would've said something like:

strSQL = strSQL & "(First 60 characters of the SQL code)"
strSQL = strSQL & "(next 60 characters")

etc.

I'd follow this up at the end with strSQL.execute

Ken

RE: Continue line of code on next line

That method certainly works fine, but it takes up a lot of space, and when you're wrapping lines because you're running out of space, seems rather counterproductive.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See Thread181-473997 for more pointers.

RE: Continue line of code on next line

The _

Can be tricky at times. Make sure you don't forget commas between field names.

I've also used the:

strSQL = (60 lines)
strSQL - strSQL & (next 60 lines)

With success.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join | Advertise

Copyright © 1998-2022 engineering.com, Inc. All rights reserved.
Unauthorized reproduction or linking forbidden without expressed written permission. Registration on or use of this site constitutes acceptance of our Privacy Policy.

Engineering.com

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.

Join Us Close

priceberded.blogspot.com

Source: https://www.tek-tips.com/viewthread.cfm?qid=569274

Post a Comment for "Sql Server Continue Long String on Next Line"