SQL2K Help! SQL Union Query And Varchar / Integer Conversion Problems =(
Aug 8, 2007
Hi, I need help. Understatement of the year right now, too =
So... I've created a stored procedure that partially pulls a SQL union query to give me a complete one-line result set of a bunch of data... four separate selects comprise the query.
The tables are structured identically to each other, but the values being pulled are specific and distinct. All of the non-date values stored are varchar values in the tables, and yet when I execute the SQL union query, I get the error message: Syntax error converting the varchar value to a column of data type int.
I know SQL does implicit conversions, however Im not sure why it's trying to do that with this query, I suppose. it should have been straightforward.
Any suggestions? Here is the query logic to look at, in case I'm missing the obvious
exec('
SELECT ACCOUNT, LNAME, FNAME, SEX, DOB, cast(MA_ContentValue as decimal) as MA_ContentValue, cast(MA_DOS as smalldatetime) as MA_DOS,
cast(LDL_ContentValue as decimal) as LDL_ContentValue, cast(LDL_DOS as smalldatetime) as LDL_DOS,
cast(HgbA1C_ContentValue as decimal)as HgbA1C_ContentValue, HgbA1C_DOS, cast(Creatinine_ContentValue as decimal) as Creatinine_ContentValue, Creatinine_DOS
FROM
(
SELECT Account, Lname, FName, Sex, DOB,MA_ContentValue, MA_DOS,
0 as LDL_ContentValue, 0 as LDL_DOS,
0 as HgbA1C_ContentValue, 0 as HgbA1C_DOS,
0 as Creatinine_ContentValue, 0 as Creatinine_DOS
FROM dbo.vwDiabetic_MicroalbuminTop3
UNION
SELECT Account, Lname, FName, Sex, DOB, 0 as MA_ContentValue, 0 as MA_DOS,
LDL_ContentValue, LDL_DOS,
0 as HgbA1C_ContentValue, 0 as HgbA1C_DOS,
0 as Creatinine_ContentValue, 0 as Creatinine_DOS
FROM dbo.vwDiabetic_LDLTop3
UNION
SELECT Account, Lname, FName, Sex, DOB, 0 as MA_ContentValue, 0 as MA_DOS,
0 as LDL_ContentValue, 0 as LDL_DOS,
HgbA1C_ContentValue, HgbA1C_DOS,
0 as Creatinine_ContentValue, 0 as Creatinine_DOS
FROM dbo.vwDiabetic_HgbA1CTop3
UNION
SELECT Account, Lname, FName, Sex, DOB, 0 as MA_ContentValue, 0 as MA_DOS,
0 as LDL_ContentValue, 0 as LDL_DOS,
0 as HgbA1C_ContentValue, 0 as HgbA1C_DOS,
Creatinine_ContentValue, Creatinine_DOS
FROM dbo.vwDiabetic_CreatinineTop3
) tbl1
')
Anything else that I can provide for someone to help me? I appreciate any/all feedback!
View 11 Replies
ADVERTISEMENT
Nov 25, 2007
this is in form VB
Private Sub orderidtxbx_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles orderidtxbx.Click
sqlconnection = New SqlConnection("Data Source= xxxx;Initial Catalog = xxxx; user ID = sa; Password = xxxxx;")
sqlcommand = New SqlCommand("select Customer.LastName, Customer.FirstName from customer where ticket.ticketid ='" & orderidtxbx.Text & "'", sqlconnection)
sqlconnection.Open()
sqldatareader = sqlcommand.ExecuteReader()
ListBox1.Items.Add(sqldatareader.Item("LastName") & " " & sqldatareader.Item("FirstName")
error msg The multi-part identifier "ticket.ticketid" could not be bound
query in sql 2005,I need to make store procedure.
SELECT Itinerary.FlightID, Itinerary.Class, Itinerary.Quantity, Ticket.Date, Flight.FlightNo, Flight.AirLine, Flight.DepartureDate, Flight.ArrivalDate,
Flight.DepartureTime, Flight.ArrivalTime, Flight.Price, Departure.DepartureLocation, Arrival.ArrivalLocation,GST=convert(int,Itinerary. Quantity*0.06*Flight.Price),PST=convert(int,Itiner ary.Quantity*0.07*Flight.Price),TotalPrice=convert (int,(Itinerary.Quantity*0.06*Flight.Price)+(Itine rary.Quantity*0.07*Flight.Price)+Flight.Price)
FROM Flight INNER JOIN
Itinerary ON Flight.FlightID = Itinerary.FlightID INNER JOIN
Ticket ON Itinerary.TicketID = Ticket.TicketID INNER JOIN
Departure ON Flight.DepartureLocationID = Departure.DepartureID INNER JOIN
Arrival ON Flight.ArrivalLocationID = Arrival.ArrivalID
WHERE (Itinerary.ticketid = '@Itinerary.ticketid')
if i change WHERE (Itinerary.ticketid = 1)
it will read the data in the table.
I need to refer that itinerary.ticketid into textbox in form that's why i make like this WHERE (Itinerary.ticketid = '@Itinerary.ticketid') but i don't know what is worng with this.
This error Msg 245, Level 16, State 1, Line 2
Conversion failed when converting the varchar value '@Itinerary.ticketid' to data type int(but my ticketid value already integer not varchar).
View 4 Replies
View Related
Jul 23, 2005
I have a table of zip codes, some with Canadian zips. I'd like to takea zip code and search for nearby zips. For example:Dim theZip As Integer = textbox1.text....Parameter.Add(@ziplow, SqlDbType.Int, 5).Value = (theZip - 10)....Parameter.Add(@ziphigh, SqlDbType.Int, 5).Value = (theZip + 10)SELECT * from ZIPCODES where Cast(zip_code as Integer) BETWEEN @lowzipAND @highzipProblem is the letters in the Canadian records cannot be cast asintegers for this process. I get this error:Syntax error converting the varchar value '53151 1' to a column of datatype int.Is there a SQL query that can exclude if no cast can be made to anInteger?Thanks!Anton
View 5 Replies
View Related
Aug 29, 2007
Hi, I've created a SQL union query that grabs the top three values of a test and puts the results together on one line item by a recordnumber.
The only problem is, one value is generating the error: " Syntax error converting the varchar value '=' to a column of data type int."
This field is an operator field, so it will only display operator values ( <, >, = ). Everything seems to work BUT the union join on that column, which is a varchar data type. I need this union to work, and Im frustrated that I can't seem to figure out why I can't get the logic to work. Can someone take a look at this and help me with it?
The union query looks like this:
exec('select
RecordNumber,Sum(rank1) as HbA1CRank1,max(Operator1) as HbA1COperator1,sum(contentValue1) as HbA1CContentvalue1,max(dos1) as HbA1CDOS1,Sum(rank2) as HbA1CRank2,max(Operator2) as HbA1COperator2,sum(contentValue2) as HbA1CContentvalue2,max(dos2) as HbA1CDOS2,Sum(rank3) as HbA1CRank3,max(Operator3) as HbA1COperator3,sum(contentValue3) as HbA1CContentvalue3,max(dos3) as HbA1CDOS3
from
(SELECT DISTINCT TOP 100 PERCENT recordnumber, Rank AS rank1, cast(Operator as varchar) as Operator1, contentValue AS contentvalue1, DOS AS DOS1, 0 AS rank2, 0 as Operator2, 0 AS contentvalue2, 0 AS DOS2, 0 AS rank3, 0 as Operator3, 0 AS contentvalue3, 0 AS DOS3FROM (SELECT (SELECT COUNT(*) FROM tblDiabetic_HgbA1C_Total vw1 WHERE vw1.rECORDnUMBER = vw2.rECORDnUMBER AND vw1.ItemCode = vw2.ItemCode AND vw1.Operator = vw2.Operator AND vw1.DOS > vw2.DOS) AS Rank, * FROM tblDiabetic_HgbA1C_Total vw2) vw3WHERE (Rank = 0)ORDER BY RecordNumber
UNION
SELECT DISTINCT TOP 100 PERCENT recordnumber, 0 AS rank1, 0 as Operator1, 0 AS contentvalue1, 0 AS DOS1, Rank AS rank2, cast(Operator as varchar) as Operator2, contentValue AS contentvalue2, DOS AS DOS2, 0 AS rank3, 0 as operator3, 0 AS contentvalue3, 0 AS DOS3FROM (SELECT (SELECT COUNT(*) FROM tblDiabetic_HgbA1C_Total vw1 WHERE vw1.rECORDnUMBER = vw2.rECORDnUMBER AND vw1.ItemCode = vw2.ItemCode AND vw1.Operator = vw2.Operator AND vw1.DOS > vw2.DOS) AS Rank, * FROM tblDiabetic_HgbA1C_Total vw2) vw3WHERE (Rank = 1)ORDER BY RecordNumber
UNION
SELECT DISTINCT TOP 100 PERCENT recordnumber, 0 AS rank1, 0 as Operator1, 0 AS contentvalue1, 0 AS DOS1, 0 AS rank2, 0 as operator2, 0 AS contentvalue2, 0 AS DOS2, rank AS rank3, cast(Operator as varchar) as operator3, contentvalue AS contentvalue3, DOS AS DOS3FROM (SELECT (SELECT COUNT(*) FROM tblDiabetic_HgbA1C_Total vw1 WHERE vw1.rECORDnUMBER = vw2.rECORDnUMBER AND vw1.ItemCode = vw2.ItemCode AND vw1.Operator = vw2.Operator AND vw1.DOS > vw2.DOS) AS Rank, * FROM tblDiabetic_HgbA1C_Total vw2) vw3WHERE (Rank = 2)ORDER BY RecordNumber )tblHgA1C
group by RecordNumber
')GO
Can anyone help? It looks right to me, I just can't figure out why the error keeps coming up =
Thank you!
View 4 Replies
View Related
Oct 9, 2007
Hello Guys,Have been getting this error(
Implicit conversion from data type ntext to varchar is not allowed. Use the CONVERT function to run this query.
) when running on the live environment but it was fine when run locally. If anyone has similar problem please let me know the fix you have done.
Thank you.
View 2 Replies
View Related
Jan 25, 2004
In my database I have a table called "users" with a varchar-field that holds categori-id's commaseparated, collected from my other table "category". I do this to control access for my users, some users are only allowed access to some categories. I would like to run a statement sort of like this:select categoryname
from category
where catid in (select categories from user where userid = 12)Naturally, because catid and the field categories have different datatypes I get the error "Syntax error converting the varchar value '340, 344, 356' to a column of data type int."
Is there any way I can bypass this keeping the commaseparated values and without making a new normalized table instead?
(same question is also posted at sql-server-performance.com forums)
View 6 Replies
View Related
Feb 3, 2005
I have always programmed my ASP pages with MS Access DB's and we recently got a SQL Server 2000. So, I'm totally new to SQL Server 2000.
I trying to retrieve data from a table in SQL, based on values from two input fields (text fields) on a form in the web page.
To process the form, I am using the following syntax:
Set oRs = oConn.Execute("SELECT BBILNAM, BTWP, BTXP, BPARCEL, BBILADD, BBILCTYST, BBILZIP5 FROM TESTdb WHERE BTWP = 'TWP' AND BPARCEL = 'PARCEL'")
SQL Fields in Table TESTdb are (BTWP = numeric field) and (BPARCEL = text field)
I realize that the problem is that I'm comparing a numeric field in my table, to a text field from my form, but don't know how to convert the text field to a numeric field, prior to the execution of the select statement. I'm hoping someone can point me in the right direction. Thanks!
View 2 Replies
View Related
Mar 13, 2002
hi i want to insert the varchar value inter column, how can i convert the values and insert in to the record if i give direct column name i am getting a message
insert into EMP(id)
SELECT name from STU
i am getting a message like this
Syntax error converting the varchar value '200.00' to a column of data type int.
View 3 Replies
View Related
Feb 29, 2008
I have a table like this:
tbl_Projects
-------------------------
ProjID | Description
-------------------------
1 | First
2 | Second
3 | Third
I want to write a SELECT statement that will output in this format:
1 - First
2 - Second
etc...
I've tried these two statements:
SELECT (ProjID + ' - ' + Description) AS Projects
FROM tbl_Projects
//Error: Conversion failed when converting the varchar value 'First' to data type int.
and
SELECT CONCAT(ProjID, CONCAT(' - ', Description)) AS Projects
FROM tbl_Projects
//Error: The data types int and varchar are incompatible in the concat operator.
Is there any way to concatenate an int value with a varchar value?
View 3 Replies
View Related
Sep 19, 2014
SQL command ....
declare @found int;
set @found = 'select sid from StickyContent where StickyId='+0+' and UserId='+171
exec (@found)
delete from StickyContent where sid = @found
I need to pass this statement from my UI i.e in a single query. I am getting this error.
"Conversion failed when converting the varchar value 'select sid from StickyContent where StickyId=' to data type int.
"
View 2 Replies
View Related
Apr 3, 2008
Haiii..
I save number in database as varchar, but i want to call it back and
convert as double/int. Can it be done
View 13 Replies
View Related
Jul 7, 2007
HiAm Using ASP.NET With SQL SERVER 2005 Backend
AGENT CODE
3008000003
NAME
agent code dropdownlist values like 1005000006,2009000002,3008000003select dropdownlist value it display corresponding values related to that codewhen i select first 2 values its run properly,But when i select 3008000003 i will get following error messagein SQL SERVER 2005 Agent Code Date Type is "bigint"" The conversion of the nvarchar value '3008000003' overflowed an int
column. Maximum integer value exceeded. Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code. Exception Details:
System.Data.SqlClient.SqlException: The conversion of the nvarchar value
'3008000003' overflowed an int column. Maximum integer value
exceeded.Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace: Please Help me to solve this issueThanks With RegardsS.Senthil Nathan
View 4 Replies
View Related
Apr 30, 2008
Good day all.
Let's see if I can stump you with this one.....
Code Snippet
SELECT Account.New_DistributorAccountNumber, Account.New_NameonBill, ActivityPointer.Subject, ActivityPointer.CreatedOn AS ExprX
FROM Account INNER JOIN
ActivityPointer ON Account.AccountId = ActivityPointer.RegardingObjectId
UNION
SELECT Account_1.New_DistributorAccountNumber AS Expr1, Account_1.New_NameonBill AS Expr2, ActivityPointer_1.CreatedOn AS Expr19,
ActivityPointer_1.Subject AS Expr20
FROM Account AS Account_1 INNER JOIN
Contact AS Contact_1 ON Account_1.AccountId = Contact_1.AccountId INNER JOIN
ActivityPointer AS ActivityPointer_1 ON Contact_1.ContactId = ActivityPointer_1.RegardingObjectId
gives the error mentioned above. Each select statement, when run separately, works fine. Any clues?
Thank you in advance
View 4 Replies
View Related
Jan 10, 2002
Hi:
here i am giving one example with Emp table and fields ssn,empjoindate
I have a table with field empjoindate as varchar(10).I need number of employees joined between 12/23/01 and 01/04/02.I ran this query using select ssn from EMP where convert(varchar(10),empjoindate,101) between '12/23/01' and '01/04/02'.it is not fetching any data.
Please help me
Thanks
Tej
View 8 Replies
View Related
Aug 4, 2006
Hi,
Can someone please explain to me how the datapages in Microsoft SQL Server 2000 works. The pages are supposed to be 8K, that is 8192 bytes of which only 8060 are accessible for data storage (due to overhead).
Now, I currently have a table containing 8 fields. Two of these fields are varchar and should be converted to nvarchar. One of the varchar fields is limited to 255 characters and the other to 4000 characters. When I convert the 255 characters field to nvarchar it works just fine, but when I want to convert the 4000 characters field I get an error from MS SQL saying that it gets to big. Is the error only for the 4000 characters field (which growths to 8000 bytes when using nvarchar instead of varchar) or must the whole table fit into one datapage?
Could a blob maybe solve my problem, or will I face new problems when storing unicode characters in a blob?
Thanks in advance
View 3 Replies
View Related
May 30, 2008
I have Field which contains Date in dd/mm/yy fromat. I need to convert it into DateTime format so that it can be processed.
Please help
View 2 Replies
View Related
Jan 12, 2008
I am getting an issue when I am using a stored proc from a view.
I am to returning values, one being a varchar(50).
When I run the view, the values for this column and all others are returned fine.
When I run the stored procedure, the following error is shown:
Conversion failed when converting the varchar value 'ejoy' to data type int.
All other values return fine bar this one column and as I said its already a varchar in the table so I don't know why sql server (2005) thinks I want to convert it, I don't and at no point have tried to.
Below is my query statement
quote:SELECT u.User_fname, pv.PV_address, p.Start_monitoring, p.Last_monitoring, p.Period_of_monitoring, m.Ongoing_maintenance,
m.Savings_for_inverter_replacement, m.Monitoring, m.Total_anual_maint_and_monitor
FROM PerformanceData p, MonitoringCost m, Photovoltaic pv, Users u
WHERE p.Performance_id=m.MonitoringCost_id and
pv.PV_id=p.Performance_id and
pv.PV_id=m.MonitoringCost_id and
u.User_id =p.Performance_id and
u.User_id =pv.PV_id and
u.User_id = m.MonitoringCost_id
This error has been displayed
quote:Conversion failed when converting the varchar value 'ejoy' to data type int.
Any ideas much appreciated...
View 16 Replies
View Related
Nov 12, 2006
Hi All,
Is it possible to convert a nText column in the source to varchar in the destination. I tried using a DataConversion block but there is no option for Ntext, I think am misising somehting here. Can someone guide me here?
thanks in advance,
View 4 Replies
View Related
Sep 14, 2007
I was just wondering if someone could help me with data conversion from ntext to varchar(max) in SSIS.
I have managed to do conversion from ntext to varchar(n) using the following two step process
(1) ntext to text stream [DT_TEXT]
(2) text stream to string[DT_STR]
Thanks,
Asaf
View 3 Replies
View Related
Nov 22, 2007
Hello All,
I am querying from a table which has all varchar values. I want to display the result in graph and hence would need the varchar to be converted to Decimal. But I am getting the error : Error converting data type varchar to Numeric. Here is the SELECT code: Can you please help me do this? I'll post the script in the next post in 10 minutes....
View 3 Replies
View Related
Aug 2, 2007
why do i have this error? not converting a varchar into int 1 ALTER PROCEDURE dbo.RevertDB
2 (
3 @Log varchar(MAX) = NULL OUTPUT
4 )
5
6 /* Reverts Database to original "Clean" State */
7 AS
8 SET NOCOUNT OFF
9 DECLARE @RowsInDB AS int
10 SET @Log = 'RevertDB Started at ' + CAST(GETDATE() AS varchar(50)) + '<br />'
11
12 /* *** Disable Constraints ***
13 ALTER TABLE Booking NOCHECK CONSTRAINT ALL
14 ALTER TABLE InventoryPC NOCHECK CONSTRAINT ALL
15 ALTER TABLE PC NOCHECK CONSTRAINT ALL
16 ALTER TABLE Platform NOCHECK CONSTRAINT ALL*/
17
18 /* *** Start Deletes *** */
19 DELETE FROM Booking
20 SET @Log = @Log + 'Clear Table Booking - Done' + '<br />'
21 SET @RowsInDB = (SELECT COUNT(BookingID) FROM Booking)
22 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
23
24 DELETE FROM InventoryPC
25 SET @Log = @Log + 'Clear Table InventoryPC - Done' + ''
26 SET @RowsInDB = (SELECT COUNT(InventoryID) FROM InventoryPC)
27 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
28
29 DELETE FROM PC
30 SET @Log = @Log + 'Clear Table PC - Done' + '<br />'
31 SET @RowsInDB = (SELECT COUNT(PCID) FROM PC)
32 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar(10)) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
33
34 DELETE FROM Platform
35 SET @Log = @Log + 'CLear Table Platform - Done' + ''
36 SET @RowsInDB = (SELECT COUNT(PlatformID) FROM Platform)
37 SET @Log = @Log + '-- Rows Affected: ' + CAST(@@ROWCOUNT AS varchar) + ', Rows in Table: ' + CAST(@RowsInDB AS varchar(10)) + '<br />'
38
39 /* *** Enable Constraints ***
40 ALTER TABLE Booking WITH CHECK CHECK CONSTRAINT ALL
41 ALTER TABLE InventoryPC WITH CHECK CHECK CONSTRAINT ALL
42 ALTER TABLE PC WITH CHECK CHECK CONSTRAINT ALL
43 ALTER TABLE Platform WITH CHECK CHECK CONSTRAINT ALL*/
44
45 SET @Log = @Log + '*** End Truncates ***' + '<br />'
46 /* *** End Truncates *** */
47
48 /* *** Start Insert Platform *** */
49 SET @Log = @Log + 'Start Insert Platform' + '<br />'
50
51 EXEC dbo.InsertPlatfrom 'Windows XP SP2 Professional Edition', 'Some description for Windows XP SP2 Professional Edition over here …'
52 EXEC dbo.InsertPlatfrom 'Windows Vista Ultimate', 'See everything you''re working on more clearly with Windows Aero, and quickly switch between windows or tasks using Windows Flip 3D and Live Thumbnails. You can easily find what you need—when you need it―with Instant Search and live icon previews that display the actual contents of your files. And while you''re at it, give your personal productivity a boost with instant access to the information you care about using Windows Sidebar and Gadgets. Put these easy-to-use and customizable mini-applications on your desktop and reveal the information you''re looking for at a glance. Website: http://www.microsoft.com/windows/products/windowsvista/seeit/default.mspx'
53 EXEC dbo.InsertPlatfrom 'Apple Mac OS X Tiger', 'Some description for Apple Mac OS X Tiger over here …'
54 EXEC dbo.InsertPlatfrom 'Apple Mac OS X Leopard', 'Desktop: The new look of Leopard showcases your favorite desktop image and puts new file Stacks at your fingertips for a stunning, clutter-free workspace. Finder: Browse your files like you browse your music with Cover Flow. Time Machine: See how your system looked on any given day and restore files with a click. Website: http://www.apple.com/macosx/leopard/features/'
55 EXEC dbo.InsertPlatfrom 'Red Hat Linux', 'Some description for Red Hat Linux over here …'
56
57 SET @Log = @Log + 'Rows In Platform: ' + CAST((SELECT COUNT(PlatformID) FROM Platform) AS varchar(10)) + '<br />'
58 /* *** Start Insert PC *** */
59 SET @Log = @Log + 'Start Insert PC' + '<br />'
60
61 DECLARE @WinXP int, @WinVista int, @OSXTiger int, @OSXLeopard int, @RedHat int
62 SET @WinXP = (SELECT PlatformID FROM Platform WHERE Title = 'Windows XP SP2 Professional Edition')
63 SET @WinVista = (SELECT PlatformID FROM Platform WHERE Title = 'Windows Vista Ultimate')
64 SET @OSXTiger = (SELECT PlatformID FROM Platform WHERE Title = 'Apple Mac OS X Tiger')
65 SET @OSXLeopard = (SELECT PlatformID FROM Platform WHERE Title = 'Apple Mac OS X Leopard')
66 SET @RedHat = (SELECT PlatformID FROM Platform WHERE Title = 'Red Hat Linux')
67
68 EXEC dbo.InsertPC 'Fusion PC One', 'Description here ...', 'Intel Core2 Duo E6600 2.4 GHz 1066MHz', '1GB Dual Channel DDR2 667 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3', '22" 3000:1 Wide Screen LCD', @WinXP
69 EXEC dbo.InsertPC 'Fusion PC Two', 'Description here ...', 'Intel Core2 Duo E6850 3 GHz 1333MHz', '2GB Dual Channel DDR2 800 SDRAM', '240GB SATA2 NCQ HDD', 'NVIDIA GeForce 8800 Ultra 256MB GDDR3 SLI', '24" 3000:1 Wide Screen LCD', @WinVista
70 EXEC dbo.InsertPC 'Fusion PC Three', 'Description here ...', 'AMD Athlon 64 X2 Dual Core 6000+ 3 GHz', '2GB Dual Channel DDR2 667 SDRAM', '240GB SATA2 NCQ HDD', 'ATI Radeon Cross Fire 2900 256MB GDDR3', '24" 3000:1 Wide Screen LCD', @WinVista
71 EXEC dbo.InsertPC 'Fusion X1', 'Description here ...', 'Intel Core2 Extreme Q6850 3 GHz 1333MHz', '6GB Dual Channel DDR2 800 SDRAM', '500GB SATA2 NCQ HDD', 'NVIDIA GeForce 8800 Ultra 256MB GDDR3 SLI', '30" 3000:1 Wide Screen LCD', @OSXLeopard
72 EXEC dbo.InsertPC 'Fusion X2', 'Description here ...', 'AMD Athlon 64 FX 74 3 GHz', '6GB Dual Channel DDR2 800 SDRAM', '500GB SATA2 NCQ HDD', 'NVIDIA GeForce 8900 Ultra SLI 256MB GDDR3', '30" 3000:1 Wide Screen LCD', @WinVista
73 EXEC dbo.InsertPC 'Fusion Tiger 1', 'Description here ...', 'Intel Core2 Duo E6600 2.4 GHz 1066MHz', '2GB Dual Channel DDR2 800 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3 SLI', '22" 3000:1 Wide Screen LCD', @OSXTiger
74 EXEC dbo.InsertPC 'Fusion Linux 1', 'Description here ...', 'AMD Athlon 64 X2 6000+ 3 GHz', '1GB Dual Channel DDR2 800 SDRAM', '120GB SATA2 NCQ HDD', 'NVIDIA GeForce 8600 256MB GDDR3', '22" 3000:1 Wide Screen LCD', @RedHat
75
76 SET @Log = @Log + 'Rows In PC: ' + CAST((SELECT COUNT(PCID) FROM PC) AS varchar(10)) + '<br />'
77
78 /* *** Start Insert Inventory *** */
79 SET @Log = @Log + 'Start Insert Inventory' + '<br />'
80
81 DECLARE @F1 int, @F2 int, @F3 int, @FX1 int, @FX2 int, @FT1 int, @FR1 int
82 SET @F1 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC One')
83 SET @F2 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC Two')
84 SET @F3 = (SELECT PCID FROM PC WHERE Title = 'Fusion PC Three')
85 SET @FX1 = (SELECT PCID FROM PC WHERE Title = 'Fusion X1')
86 SET @FX2 = (SELECT PCID FROM PC WHERE Title = 'Fusion X2')
87 SET @FT1 = (SELECT PCID FROM PC WHERE Title = 'Fusion Tiger 1')
88 SET @FR1 = (SELECT PCID FROM PC WHERE Title = 'Fusion Linux 1')
89
90 EXEC dbo.InsertInventory 10, @F1, 2.5, 'iCluster Fusion One'
91 EXEC dbo.InsertInventory 10, @F2, 2.5, 'iCluster Fusion Two'
92 EXEC dbo.InsertInventory 10, @F3, 2.5, 'iCluster Fusion Three'
93 EXEC dbo.InsertInventory 6, @FX1, 6, 'iCluster Fusion X1'
94 EXEC dbo.InsertInventory 6, @FX2, 6, 'iCluster Fusion X2'
95 EXEC dbo.InsertInventory 10, @FT1, 3, 'iCluster Fusion Tiger One'
96 EXEC dbo.InsertInventory 30, @FR1, 2, 'iCluster Fusion Linux One'
97
98 SET @Log = @Log + 'Rows In Inventory: ' + CAST((SELECT COUNT(InventoryID) FROM InventoryPC) AS varchar(10))
99
100 RETURN @Log
if i remove the last line then all is well. but i get "An SqlParameter with ParameterName '@Log' is not contained by this
SqlParameterCollection."
View 2 Replies
View Related
Jun 14, 2002
I need to pass a timestamp value to a varchar variable.CAST/Convert doesn't seem to help.
Any other work around ?
Thanks in advance.
View 1 Replies
View Related
Dec 6, 2006
I am trying to have the aggregate value 1 replaced by 'only one' in my results.
My data looks like this:
Customer_id (int) ; Salesperson_id
1 ; 1
2 ; 1
3 ; 1
4 ; 2
5 ; 2
6 ; 3
...this is the solution I tried:
select
case when count(convert(varchar(15), customer_id)) = 1
Then 'only one customer'
else count(convert(varchar(15), kund_id)) end as no_of_customers,
salesperson_id
from customerdb
group by
salesperson_id
...and this is the result I was hoping for
no_of_customers ; salesperson_id
3 ; 1
2; 2
only one customer;3
...but SQL server only returns: Conversion failed when converting the varchar value ...
View 1 Replies
View Related
May 26, 2008
Hi guys,
My query was working fine until I added the red writing below.
Basically what I'm doing with this is getting the lowest open purchase order number (docnum) and its matching docduedate.
Now when I run it I get
Conversion failed when converting the varchar value 'po_num' to data type int.
Any ideas? Thanks!
SELECT t3.product ,
t7.itemname ,
t2.u_vlgx_plc,
t3.shorted ,
t4.onhand ,
MIN(
CASE
WHEN t8.linestatus = 'O'
THEN t9.docnum
ELSE NULL
END) po_num,
t10.docduedate
FROM
(SELECT t0.product product ,
SUM(
CASE
WHEN t0.qty_topick <> t0.qty_picked
THEN t0.qty_topick - t0.qty_picked
ELSE 0
END) shorted
FROM rbeacon.dbo.shipline2 t0
INNER JOIN rbeacon.dbo.shiphist t1
ON t0.packslip = t1.packslip
WHERE t1.date_upld = CONVERT(VARCHAR(10), GETDATE()-1, 101)
GROUP BY t0.product
) t3
INNER JOIN comparison.dbo.vlgxplc t2
ON t2.itemcode = t3.product COLLATE Latin1_General_CI_AS
LEFT JOIN
(SELECT t0.product AS product,
SUM(t0.quantity) AS onhand
FROM rbeacon.dbo.binlocat t0
GROUP BY t0.product
) t4
ON t3.product = t4.product
INNER JOIN wbau.dbo.oitm t5
ON t3.product = t5.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS
LEFT JOIN wbau.dbo.ocrd t6
ON t5.cardcode = t6.cardcode
INNER JOIN wbau.dbo.oitm t7
ON t3.product = t7.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS
LEFT JOIN wbau.dbo.por1 t8
ON t3.product = t8.itemcode COLLATE SQL_Latin1_General_CP850_CI_AS
LEFT JOIN wbau.dbo.opor t9
ON t8.docentry = t9.docentry
LEFT JOIN comparison.dbo.podatetest('po_num') t10
ON t10.docnum = t9.docnum
WHERE t3.shorted <> 0
GROUP BY t3.product ,
t7.itemname ,
t2.u_vlgx_plc,
t3.shorted ,
t4.onhand ,
t6.cardname,
t10.docduedate
ORDER BY t2.u_vlgx_plc,
t6.cardname ,
t3.product
View 9 Replies
View Related
Jan 30, 2008
Basically, I'm trying to take two dates and find the difference in hours b/t the two, sql server 2000. I've tried change the variables out from datetime to varchars even though it shouldn't matter. When I put the block of code out of the stored procedure and run it in line it works fine, I'M LOST.........
I get the errors everytime it runs into the first block, I get the error again when the block is hit again farther down in the procedure. I get:
Server: Msg 242, Level 16, State 3, Procedure tmpRyan_spRail_Job_NoMovement, Line 211
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Server: Msg 242, Level 16, State 1, Procedure tmpRyan_spRail_Job_NoMovement, Line 360
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
ERR dates Aug 4 2005 11:16PM.
Server: Msg 242, Level 16, State 3, Procedure tmpRyan_spRail_Job_NoMovement, Line 211
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Server: Msg 242, Level 16, State 1, Procedure tmpRyan_spRail_Job_NoMovement, Line 360
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
ERR dates Aug 3 2005 12:35PM.
Server: Msg 241, Level 16, State 1, Procedure tmpRyan_spRail_Job_NoMovement, Line 211
Syntax error converting datetime from character string.
Code:
Declare
,@CodePair varchar(10
,@CodePairTimeDiff dec ,
@tmpTimeVar datetime ,
@tmpTimeCharVar varchar(30)
IF @NextStatusDate IS NOT NULL AND @StatusDate IS NOT NULL
BEGIN
set @tmpTimeCharVar = DATEDIFF(SECOND, @NextSTatusDate, @StatusDate)
set @tmpTimeVar =
(
CASE WHEN @tmpTimeCharVar/3600<10 THEN '0' ELSE '' END
+ RTRIM(DATEDIFF(SECOND,@NextSTatusDate, @StatusDate)/3600)
+ ':' + RIGHT('0'+RTRIM((@tmpTimeCharVar % 3600) / 60),2)
+ ':' + RIGHT('0'+RTRIM((@tmpTimeCharVar % 3600) % 60),2)
)
END
IF @@ERROR <>0
PRINT 'ERR dates' + Convert(varchar(20), @NextStatusDate) + '.'
inside update statement
,CodePairTimeDiff = CONVERT(dec, (100 * DATEPART(HOUR, @tmpTimeVar)
+ DATEPART(MINUTE, @tmpTimeVar))) / 60
View 12 Replies
View Related
Oct 3, 2005
Hi,
I am having an issue with a Report in SSRS against a Sybase db.
The dataset for the report is a Sybase stored proc which is passed a parameter (varchar). When I run the proc in Sybase it runs fine, when I run it in SSRS in the data tab it runs fine, but when I try to preview the report, or run from IE after deploying it I get the following error:
An error has occurred during report processing. (rsProcessingAborted) Get Online Help
Query execution failed for data set 'Table_1'. (rsErrorExecutingCommand) Get Online Help
The given type name was unrecognized
Looks like it is an error converting the string in SSRS to a varchar in Sybase, but I don't know how to fix it.
If I create a table with an identity (int) column and the varchar column, join this to the proc and pass the int as the parameter the report works fine!! (This is not an option in production though.)
I am using SybaseASE OLE DB Provider Version 02.70.0032
Any ideas?
TIA,
Guytz
View 1 Replies
View Related
Oct 2, 2014
When you converting varchar to date time
SELECT convert(varchar,getdate())
What is the getdate here
i.e. we are converting any value to today's date
View 9 Replies
View Related
Dec 15, 2014
How do I pass a variable to an INT calculation?
CREATE PROC CLEAR_MY_TABLE
@TableStat varchar(30)
AS
If OBJECT_ID('MyDB.dbo.' + @TableStat + '') is not null
BEGIN
---PRINT 'I FOUND THE TABLE'
DECLARE @count INT = -1;
SELECT @count = (Select COUNT(*) FROM [dbo]. + @TableStat);
IF (@count > 0)
BEGIN
TRUNCATE TABLE @TABLESTAT
END
View 8 Replies
View Related
Mar 6, 2015
I have a statement that I'm having trouble converting:
select * from emails join InternalContacts On emails.EmailAddress = InternalContacts.EmailID
When I run this I get -
Conversion failed when converting the varchar value 'credentialing@floridaeyeclinic.com' to data type int.
What is the correct syntax to convert?
View 2 Replies
View Related
Aug 14, 2015
I have column moddat which is of varchar(10,null)
Here is my data:
20020415
20020508
19991104
19990701
20040514
20021112
20020124
19990628
20020514
20010822
I want those data in this format YYYY-MM-DD
How to convert varchar to datetime?
View 2 Replies
View Related
Mar 6, 2008
I am recieving the following error when executing the following code. Field MonData is nvarchar (80), the only integer feild in the concatination is @Cnt all other fields are varchar or nvarchar. If I remove the everything past space(22) it works fine. I double checked the length and it does not exceed 80 bytes.
Can anyone see what I am doing wrong?
INSERT INTO tbl_Export
Select DISTINCT TOP(1) space(32) + '9' + space(2) + @Cnt + space(2) + Sys + space(2) +
Prin + space(22) + 'TEN' + space(1) + 'ZZ' As MonData
FROM dbo.Trans
WHERE Sys = @vwSys AND Prin = @vwPrin
ERROR:
Conversion failed when converting the varchar value 'TEN' to data type int.
Any input is welcome, thanks so much.
View 8 Replies
View Related
Jan 23, 2008
I have a Condition in my stored procedure
AND tt.RevenueTypeID LIKE CASE WHEN @iRevenueTypeID = -1 THEN '%' ELSE @iRevenueTypeID END
@iRevenueTypeID is declared as VARCHAR(6)
When i am passing 'PRP in the the Stored procedure for iRevenueTypeID
it was working fine till now but now it is giving error as
Conversion failed when converting the varchar value 'PRP' to data type int.
What i am doing wrong?
View 3 Replies
View Related
Jul 31, 2006
Hi,
I have a parameter @name varchar(50)
but the table has a field with datatype GUID
how I can convert varchar to guid before insertion...
Thanks
View 1 Replies
View Related