can anyone help me figure out why when i run the following stored
procedure i get the error:
(1460 row(s) affected)
Msg 245, Level 16, State 1, Procedure SP_SALESTRENDS, Line 40
Conversion failed when converting the varchar value 'X' to data type
int.
SP:
--STORED PROCEDURE FOR INVOICE TRENDS:
--To use Stored Procedure use the following code:
--EXEC SP_INSPECTIONSU MRY (MONTH), (OFFICE)
-- (OFFICE) CAN BE: BGR FOR BANGOR, SP FOR SOUTH PORTLAND, NH FOR NEW
HAMPSHIRE, UNH FOR UNH
-- (REPORT) CAN BE: PRODUCT CODE FOR REPORT BROKEN OUT BY PRODUCT CODE
-- EXEC SP_SALESTRENDS BGR, INVOICED, 2006, X
ALTER PROCEDURE SP_SALESTRENDS
@OFFICE VARCHAR(30),
@REPORT VARCHAR(30),
@VARYEAR INT,
@CODE VARCHAR(30)
AS
IF @REPORT='INVOIC ED'
SELECT YEAR(I.INVOICED AT) AS VARYEAR, MONTH(I.INVOICE DAT) AS VARMONTH,
SUM(I.STOTAL) AMOUNT, P.PERSON, P.PRODUCT, C.DESCRIPTN
INTO #TEMP_SALESTREN DS
FROM OPENQUERY(PROJE CTS, '
SELECT PROJECT, INVOICEDAT, STOTAL
FROM INVSUMYR') I
LEFT JOIN
(SELECT *
FROM OPENQUERY(PROJE CTS, '
SELECT NUMBER, PRODUCT, PERSON
FROM PROJMAST
')) P
ON (LTRIM(I.PROJEC T)=LTRIM(P.NUMB ER))
LEFT JOIN
(SELECT PC, DESCRIPTN
FROM OPENQUERY(PROJE CTS, '
SELECT PC, DESCRIPTN
FROM PRODCODE')) C
ON (C.PC=P.PRODUCT )
GROUP BY YEAR(I.INVOICED AT), MONTH(I.INVOICE DAT), P.PERSON, P.PRODUCT,
C.DESCRIPTN
ORDER BY VARYEAR, VARMONTH
-- INVOICED REPORT BROKEN OUT BY OFFICE
IF @REPORT='INVOIC ED' AND @CODE=1 AND @VARYEAR=1234 AND
@OFFICE='NORRIS '
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @CODE!=1 AND @VARYEAR=1234
SELECT VARYEAR, VARMONTH, SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT=@CODE
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED'AND @CODE!=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT=@CODE AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='NORRIS ' AND @CODE=1 AND
@VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='BGR' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('G', 'H', 'I', 'J', 'K', 'L')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='BGR' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('G', 'H', 'I', 'J', 'K', 'L') AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='SP' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('A', 'B', 'C', 'D', 'E', 'C', 'S', '3', '4')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='SP' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('A', 'B', 'C', 'D', 'E', 'C', 'S', '3', '4') AND
VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='NH' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('W', 'X', 'Y', 'N', 'O', 'P')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='NH' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('W', 'X', 'Y', 'N', 'O', 'P') AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='UNH' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('U', 'Z', 'R', 'V')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='UNH' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('U', 'Z', 'R', 'V') AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
--END OF SALES TRENDS STORED PROCEDURE
thanks. 4 4822
Conversion failed when converting the varchar value 'X' to data type
int.
It looks to me like the problem code is:
@CODE=1
Here, you are comparing value 'X' (varchar(30)) to 1 (integer). Because
integer has a higher data type precedence than varchar, SQL Server attempts
to convert the 'X' to integer and you get the error.
I see that you are a bit loose about this but it's a good practice to always
enclose literals in single quotes. For example:
EXEC SP_SALESTRENDS 'BGR', 'INVOICED', 2006, 'X'
and
@CODE='1'
--
Hope this helps.
Dan Guzman
SQL Server MVP
<jo***@norrisin c.comwrote in message
news:11******** ************@m7 9g2000cwm.googl egroups.com...
can anyone help me figure out why when i run the following stored
procedure i get the error:
(1460 row(s) affected)
Msg 245, Level 16, State 1, Procedure SP_SALESTRENDS, Line 40
Conversion failed when converting the varchar value 'X' to data type
int.
SP:
--STORED PROCEDURE FOR INVOICE TRENDS:
--To use Stored Procedure use the following code:
--EXEC SP_INSPECTIONSU MRY (MONTH), (OFFICE)
-- (OFFICE) CAN BE: BGR FOR BANGOR, SP FOR SOUTH PORTLAND, NH FOR NEW
HAMPSHIRE, UNH FOR UNH
-- (REPORT) CAN BE: PRODUCT CODE FOR REPORT BROKEN OUT BY PRODUCT CODE
-- EXEC SP_SALESTRENDS BGR, INVOICED, 2006, X
ALTER PROCEDURE SP_SALESTRENDS
@OFFICE VARCHAR(30),
@REPORT VARCHAR(30),
@VARYEAR INT,
@CODE VARCHAR(30)
AS
IF @REPORT='INVOIC ED'
SELECT YEAR(I.INVOICED AT) AS VARYEAR, MONTH(I.INVOICE DAT) AS VARMONTH,
SUM(I.STOTAL) AMOUNT, P.PERSON, P.PRODUCT, C.DESCRIPTN
INTO #TEMP_SALESTREN DS
FROM OPENQUERY(PROJE CTS, '
SELECT PROJECT, INVOICEDAT, STOTAL
FROM INVSUMYR') I
LEFT JOIN
(SELECT *
FROM OPENQUERY(PROJE CTS, '
SELECT NUMBER, PRODUCT, PERSON
FROM PROJMAST
')) P
ON (LTRIM(I.PROJEC T)=LTRIM(P.NUMB ER))
LEFT JOIN
(SELECT PC, DESCRIPTN
FROM OPENQUERY(PROJE CTS, '
SELECT PC, DESCRIPTN
FROM PRODCODE')) C
ON (C.PC=P.PRODUCT )
GROUP BY YEAR(I.INVOICED AT), MONTH(I.INVOICE DAT), P.PERSON, P.PRODUCT,
C.DESCRIPTN
ORDER BY VARYEAR, VARMONTH
-- INVOICED REPORT BROKEN OUT BY OFFICE
IF @REPORT='INVOIC ED' AND @CODE=1 AND @VARYEAR=1234 AND
@OFFICE='NORRIS '
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @CODE!=1 AND @VARYEAR=1234
SELECT VARYEAR, VARMONTH, SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT=@CODE
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED'AND @CODE!=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT=@CODE AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='NORRIS ' AND @CODE=1 AND
@VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='BGR' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('G', 'H', 'I', 'J', 'K', 'L')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='BGR' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('G', 'H', 'I', 'J', 'K', 'L') AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='SP' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('A', 'B', 'C', 'D', 'E', 'C', 'S', '3', '4')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='SP' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('A', 'B', 'C', 'D', 'E', 'C', 'S', '3', '4') AND
VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='NH' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('W', 'X', 'Y', 'N', 'O', 'P')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='NH' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('W', 'X', 'Y', 'N', 'O', 'P') AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='UNH' AND @CODE=1 AND @VARYEAR=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('U', 'Z', 'R', 'V')
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
IF @REPORT='INVOIC ED' AND @OFFICE='UNH' AND @CODE=1 AND @VARYEAR!=1234
SELECT VARYEAR , VARMONTH , SUM(AMOUNT) AS AMOUNT
FROM #TEMP_SALESTREN DS
WHERE PRODUCT IN ('U', 'Z', 'R', 'V') AND VARYEAR=@VARYEA R
GROUP BY VARYEAR, VARMONTH
ORDER BY VARYEAR, VARMONTH
--END OF SALES TRENDS STORED PROCEDURE
thanks.
I see that you are a bit loose about this but it's a good practice to
always enclose literals in single quotes.
To clarify, I mean enclose *character* literals in single quotes.
--
Hope this helps.
Dan Guzman
SQL Server MVP
Thanks, I corrected the syntax on the @ code, and it is working now.
Dan Guzman wrote:
I see that you are a bit loose about this but it's a good practice to
always enclose literals in single quotes.
To clarify, I mean enclose *character* literals in single quotes.
--
Hope this helps.
Dan Guzman
SQL Server MVP
Thanks, I corrected the syntax on the @ code, and it is working now.
Dan Guzman wrote:
I see that you are a bit loose about this but it's a good practice to
always enclose literals in single quotes.
To clarify, I mean enclose *character* literals in single quotes.
--
Hope this helps.
Dan Guzman
SQL Server MVP
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rebecca Lovelace |
last post by:
For some reason in Enterprise Manager for SQL Server 2000, I cannot
put the following line into a trigger:
select * into #deleted from deleted
When I hit the Apply button I get the following error:
Cannot use text, ntext, or image columns in the 'inserted' or
'deleted' tables
This seems like a weird error, since I am not actually doing anything
to the inserted or deleted tables, I am just trying to make a temp
copy.
|
by: Jim |
last post by:
For some reason the compiler is telling me that I must declarethe
variable @costcenter_tmp on lines 74 and 98...but if i put a select
statement in ther (for testing) before the loop I get data back from
the temp table..
why is this happening to this temp table and no others?..heres my
code..its a little lengthy
--Fiscal Year
|
by: pb648174 |
last post by:
I have a pivot table implementation, part of which is posted below. It
returns no errors in query analyzer, but when profiler is run, it shows
that "Error 208" is happening. I looked that up in BOL and it means
that an object doesn't exist. This block of code below works fine on my
local development machine, but not on our shared development server
until I go into the tempdb and make the user have the role db_owner.
Even wierder is that...
|
by: joe pribele |
last post by:
I have this stored procedure that takes some xml as input. What I need
to is use xml as a table so that I can join other tables to the xml
and get information back that matches the criteria.
I can use dxxshredxml to put it into a regular table and everything
works great. but when I try to put it into a temp table it doesn't
work. I get an error saying Session.ACCESSMASK doesn't have a column
name ACCESS_MASK_ID.
Do I have to use a...
|
by: Timothy Perrigo |
last post by:
This bug? feature? caused a bit of havoc for us yesterday...A
reproducible example follows. Essentially, if you have a table with a
primary key called "id", and you create a temp table (via a "select
into") containing a subset of the data from the table but where the
primary key field is renamed (in the example below, it is called
"not_id"), the where clause of the following update statement (which I
would expect to generate an error...
| |
by: Timothy Perrigo |
last post by:
(PostgreSQL 8.0 beta 4 on Mac OS X 10.3.6)
I'm working on a function which creates and populates a temporary
table, then returns the number of records it has inserted. I'm getting
an error, though, after successive invocations of the function (I can
call it once successfully, but on the next call I get an error). I've
been able to reproduce the error with the following sample function:
create or replace function test() returns...
|
by: wackyphill |
last post by:
If you were doing paging of results on a web page and were interested
in grabbing say records 10-20 of a result set. But also wanted to know
the total # of records in the result set (so you could know the total #
of pages in the set).
Would it be better to query the DB table 2X. Once for Count(*). And
again for the records for the current page?
Or better to create a temp table, select the records into it, and then
get count(*) and the...
|
by: John Dalberg |
last post by:
I am getting "Input string was not in a correct format" error in a line
like this:
Int32.Parse(((DataRowView)e.Item.DataItem).Row.ItemArray.ToString())
Field #8 comes from a SQL Server stored proc. The stored proc returns a
select statement from a temp table. The temp table was created by a select
into statement like this select .........., 0.5 * another column into #temp
What data type does #8 have in the framework when it's returned...
|
by: pukivruki |
last post by:
hi,
I wish to create a temporary table who's name is dynamic based on the
argument.
ALTER PROCEDURE .
@PID1 VARCHAR(50),
@PID2 VARCHAR(50),
@TICKET VARCHAR(20)
|
by: R. K. Wijayaratne |
last post by:
Hi everyone,
I have a SPROC which selects records into a MSSQL #temp table and then
selects the records from that. I drag this SPROC onto the right-hand
pane of the DBML diagram, but the method that gets generated for the
SPROC does not have a return type. Any ideas why this is?
I am referring to Scott Guthrie's blog article here:
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |