473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Help with Error Message

Could someone help me out here? I have created a pretty large Stored
Procedure with about 5 different parameters however, when I run the
procedure I get the following error:

"Syntax error converting the varchar value 'select..."

Where do I even start to find this error?

Thanks in advance
Jul 20 '05 #1
3 1500

"DaylonRed" <EC*******@profit-tech.com> wrote in message
news:83**************************@posting.google.c om...
Could someone help me out here? I have created a pretty large Stored
Procedure with about 5 different parameters however, when I run the
procedure I get the following error:

"Syntax error converting the varchar value 'select..."

Where do I even start to find this error?

Thanks in advance


You could debug the stored procedure from Query Analyzer to find the point
where the error occurs - right-click the proc and select debug.

The error message you give seem to be incomplete - it should tell you which
data type it is trying to convert to. As a complete guess, you're building a
dynamic SQL string somewhere in the procedure, and you've tried to
concatenate a varchar and an integer, but without seeing the code I don't
really know:

select 'x' + 1 -- error due to data type precedence
go
select 'x' + cast(1 as char(1)) -- works OK
go
Simon
Jul 20 '05 #2

Thanks for responded Simon. You are right in the fact that I am trying
to concatenate some strings here but I really thought the datatypes were
consistant. Would you mind taking a look at the stored procedure? I
warn you, it is quite long. :(

alter procedure dbo.sp_copscm004 (
@Bank Integer=NULL,
@Region Integer=NULL,
@Branch Integer=NULL,
@Officer Integer=NULL,
@MinDate Datetime,
@MaxDate datetime=null
)
as

Declare
@Var_MinDate datetime,
@Var_MaxDate datetime,
@SQLMainStr varchar(8000),
@SQLWhereStr varchar(500)

Set @Var_MinDate = @Mindate
Set @Var_MaxDate = @Maxdate

If (@Bank is not Null)
Begin
Set @SQLMainStr=
'select
tbl_casemaster.acctno,
tbl_casemaster.PrimaryAcctHolder,
tbl_casemaster.ProductType,
tbl_casemaster.TaxID,
tbl_casemaster.opendate,
tbl_casemaster.closeddate,
tbl_casemaster.ChargeOff_Principle,
tbl_casemaster.ChargeOff_Fees,
tbl_casemaster.ChargeOff_Interest,
tbl_casemaster.ChargeOff_Misc,
tbl_casemaster.AcctOfficerPerm,
tbl_casemaster.AcctOfficerTemp,
tbl_casemaster.agencyused,
tbl_bank.bankname,
tbl_region.regionname,
tbl_branch.branchname
from tbl_casemaster
inner join tbl_bank
on tbl_casemaster.bankid = tbl_bank.bankid
inner join tbl_branch
on tbl_casemaster.branchid = tbl_branch.branchid
inner join tbl_region
on tbl_casemaster.regionid = tbl_region.regionid
where
(ChargeOff_Principle > 0 or
ChargeOff_Fees > 0 or
ChargeOff_Interest > 0 or
ChargeOff_Misc > 0)and
tbl_CaseMaster.bankid = ''' + @Bank + ''' and'
if (@Maxdate is not null)
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate >= ''' + Cast(@Var_MinDate as Varchar(100)) +
''' and
tbl_casemaster.opendate <= ''' + Cast(@Var_MaxDate as Varchar(100)) +
''''
end
else
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate = ''' + Cast(@Var_MinDate as Varchar(100)) +
''''
end
End
else if (@Region is not Null)
Begin
Set @SQLMainStr=
'select
tbl_casemaster.acctno,
tbl_casemaster.PrimaryAcctHolder,
tbl_casemaster.ProductType,
tbl_casemaster.TaxID,
tbl_casemaster.opendate,
tbl_casemaster.closeddate,
tbl_casemaster.ChargeOff_Principle,
tbl_casemaster.ChargeOff_Fees,
tbl_casemaster.ChargeOff_Interest,
tbl_casemaster.ChargeOff_Misc,
tbl_casemaster.AcctOfficerPerm,
tbl_casemaster.AcctOfficerTemp,
tbl_casemaster.agencyused,
tbl_bank.bankname,
tbl_region.regionname,
tbl_branch.branchname
from tbl_casemaster
inner join tbl_bank
on tbl_casemaster.bankid = tbl_bank.bankid
inner join tbl_branch
on tbl_casemaster.branchid = tbl_branch.branchid
inner join tbl_region
on tbl_casemaster.regionid = tbl_region.regionid
where
(ChargeOff_Principle > 0 or
ChargeOff_Fees > 0 or
ChargeOff_Interest > 0 or
ChargeOff_Misc > 0) and
tbl_CaseMaster.Regionid = ''' + @Region + ''' and'
if (@Maxdate is not null)
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate >= ''' + Cast(@Var_MinDate as Varchar(100)) +
''' and
tbl_casemaster.opendate <= ''' + Cast(@Var_MaxDate as Varchar(100)) +
''''
end
else
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate = ''' + Cast(@Var_MinDate as Varchar(100)) +
''''
end
End
else if (@Branch is not Null)
begin
Set @SQLMainStr=
'select
tbl_casemaster.acctno,
tbl_casemaster.PrimaryAcctHolder,
tbl_casemaster.ProductType,
tbl_casemaster.TaxID,
tbl_casemaster.opendate,
tbl_casemaster.closeddate,
tbl_casemaster.ChargeOff_Principle,
tbl_casemaster.ChargeOff_Fees,
tbl_casemaster.ChargeOff_Interest,
tbl_casemaster.ChargeOff_Misc,
tbl_casemaster.AcctOfficerPerm,
tbl_casemaster.AcctOfficerTemp,
tbl_casemaster.agencyused,
tbl_bank.bankname,
tbl_region.regionname,
tbl_branch.branchname
from tbl_casemaster
inner join tbl_bank
on tbl_casemaster.bankid = tbl_bank.bankid
inner join tbl_branch
on tbl_casemaster.branchid = tbl_branch.branchid
inner join tbl_region
on tbl_casemaster.regionid = tbl_region.regionid
where
(ChargeOff_Principle > 0 or
ChargeOff_Fees > 0 or
ChargeOff_Interest > 0 or
ChargeOff_Misc > 0)and
tbl_CaseMaster.Branchid = ''' + @Branch + ''' and'
if (@Maxdate is not null)
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate >= ''' + Cast(@Var_MinDate as Varchar(100)) +
''' and
tbl_casemaster.opendate <= ''' + Cast(@Var_MaxDate as Varchar(100)) +
''''
end
else
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate = ''' + Cast(@Var_MinDate as Varchar(100)) +
''''
end
End
else if (@Officer is not Null)
Begin
Set @SQLMainStr=
'select
tbl_casemaster.acctno,
tbl_casemaster.PrimaryAcctHolder,
tbl_casemaster.ProductType,
tbl_casemaster.TaxID,
tbl_casemaster.opendate,
tbl_casemaster.closeddate,
tbl_casemaster.ChargeOff_Principle,
tbl_casemaster.ChargeOff_Fees,
tbl_casemaster.ChargeOff_Interest,
tbl_casemaster.ChargeOff_Misc,
tbl_casemaster.AcctOfficerPerm,
tbl_casemaster.AcctOfficerTemp,
tbl_casemaster.agencyused,
tbl_bank.bankname,
tbl_region.regionname,
tbl_branch.branchname
from tbl_casemaster
inner join tbl_bank
on tbl_casemaster.bankid = tbl_bank.bankid
inner join tbl_branch
on tbl_casemaster.branchid = tbl_branch.branchid
inner join tbl_region
on tbl_casemaster.regionid = tbl_region.regionid
where
(ChargeOff_Principle > 0 or
ChargeOff_Fees > 0 or
ChargeOff_Interest > 0 or
ChargeOff_Misc > 0)and
tbl_casemaster.AcctOfficerPerm = ''' + @Officer + ''' and'
if (@Maxdate is not null)
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate >= ''' + Cast(@Var_MinDate as Varchar(100)) +
''' and
tbl_casemaster.opendate <= ''' + Cast(@Var_MaxDate as Varchar(100)) +
''''
end
else
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate = ''' + Cast(@Var_MinDate as Varchar(100)) +
''''
end
End
else
begin
Set @SQLMainStr=
'select
tbl_casemaster.acctno,
tbl_casemaster.PrimaryAcctHolder,
tbl_casemaster.ProductType,
tbl_casemaster.TaxID,
tbl_casemaster.opendate,
tbl_casemaster.closeddate,
tbl_casemaster.ChargeOff_Principle,
tbl_casemaster.ChargeOff_Fees,
tbl_casemaster.ChargeOff_Interest,
tbl_casemaster.ChargeOff_Misc,
tbl_casemaster.AcctOfficerPerm,
tbl_casemaster.AcctOfficerTemp,
tbl_casemaster.agencyused,
tbl_bank.bankname,
tbl_region.regionname,
tbl_branch.branchname
from tbl_casemaster
inner join tbl_bank
on tbl_casemaster.bankid = tbl_bank.bankid
inner join tbl_branch
on tbl_casemaster.branchid = tbl_branch.branchid
inner join tbl_region
on tbl_casemaster.regionid = tbl_region.regionid
where
(ChargeOff_Principle > 0 or
ChargeOff_Fees > 0 or
ChargeOff_Interest > 0 or
ChargeOff_Misc > 0)and'
if (@Maxdate is not null)
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate >= ''' + Cast(@Var_MinDate as Varchar(100)) +
''' and
tbl_casemaster.opendate <= ''' + Cast(@Var_MaxDate as Varchar(100)) +
''''
end
else
begin
Set @SQLWhereStr =
' tbl_casemaster.opendate = ''' + Cast(@Var_MinDate as Varchar(100)) +
''''
end
End

--exec(@SQLMainStr + @SQLWhereStr)

print(@SQLMainStr + @SQLWhereStr)
GO

DaylonRed

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
DaylonRed (Da*******@developerex.com) writes:
Thanks for responded Simon. You are right in the fact that I am trying
to concatenate some strings here but I really thought the datatypes were
consistant. Would you mind taking a look at the stored procedure? I
warn you, it is quite long. :(


You have string + integer. string is lower in the type hierarchy than int,
so it is converted to integer, and then it goes downhill from there. You
appear to nevertless put @Bank in quotes in the dynamic SQL statement,
so maybe you have declare @Bank wrongly.

Better, though, is to use sp_executesql to run the dynamic SQL, in
which case you never have to run into this in the first place.

See http://www.sommarskog.se/dynamic_sql.html#sp_executesql for an
introduction.
See also http://www.sommarskog.se/dyn-search.html#sp_executesql for a
more elaborate example.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Amanda | last post by:
From a guy in Microsoft newsgroups: | In *comp.databases.ibm-db2* there are always IBM guys | from the Toronto labs on line.Post with the | -for the love of god please help- | line...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
5
by: Marc Violette | last post by:
<Reply-To: veejunk@sympatico.ca> Hello, I'm hoping someone can help me out here... I'm a beginner ASP.NET developper, and am trying to follow a series of exercises in the book entitled...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
12
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.