?
Solved

T-SQL syntax question

Posted on 2013-11-26
5
Medium Priority
?
399 Views
Last Modified: 2013-11-27
Hi all, attached you will see a small peace of code that I am trying to run in sql, can someone give me a hand on how to work this properly?
Thanks.
11-26-13.txt
0
Comment
Question by:bfuchs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 25

Assisted Solution

by:chaau
chaau earned 1500 total points
ID: 39679436
You need to escape the single quotes properly. Use two single quotes inside string literals, like this:
declare @p1 varchar(500)
set @p1=' Day >= ''01/01/2006'' AND EmployeeID IN (SELECT EmployeesID FROM EmployeesUnitstbl WHERE Unit = ''abc'') and FacilityID = 1234'
EXEC "dbo"."proc_FilterOrientNotes_Test" @P1 

Open in new window

0
 
LVL 22

Assisted Solution

by:Kelvin Sparks
Kelvin Sparks earned 500 total points
ID: 39679442
Is this sql you have inside of Access, or is this being run in SQL Server? That is, where are you running this from?


Kelvin
0
 
LVL 4

Author Comment

by:bfuchs
ID: 39679488
Hi thanks for replying,
    This is being passed as an stored procedure argument from access to sql, just placed the peace of code from where I was trying to debug it in SSMS.
However, will try modify the code according to what chaau suggested and let you know.
0
 
LVL 25

Accepted Solution

by:
chaau earned 1500 total points
ID: 39679517
If it is a passed code you need to use a different approach. Here is a small chunk of VBA code that is calling an SQL Server stored procedure:
Public dbconn As ADODb.Connection
Dim cmd As New ADODb.command
Dim rs As New ADODb.Recordset
Dim param As New ADODb.Parameter

Set dbconn = New ADODb.Connection
dbconn.ConnectionString = GetServerCon

dbconn.Open dbconn.ConnectionString

Set cmd = New ADODb.command
cmd.ActiveConnection = dbconn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "dbo.proc_FilterOrientNotes_Test"

Set param = cmd.CreateParameter(_
   "p1", adVarChar, adParamInput, 500, " Day >= '01/01/2006' AND EmployeeID IN (SELECT EmployeesID FROM EmployeesUnitstbl WHERE Unit = 'abc') and FacilityID = 1234"
cmd.Parameters.Append param

rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open cmd

Open in new window

As you can see, you do not need to escape the single quotes in VB code, as the outer quotes are the double quotes.
0
 
LVL 4

Author Closing Comment

by:bfuchs
ID: 39682042
Actually from kelvinsparks question & chaau's two answers I figured out where the problem were indeed...
it was something wrong with the sql statement itself (ambiguous field name..).
Thanks very much for your help guys!!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question