Thanks for previous help, I am however continuing to have problems as I attempt to search a table for a value keyed by the user (e.g. AccessionPresent= 3624-01). The input value that is being searched against is stored in the table as an INT. I have cast the INT to a VARCHAR on the line described as "MSQL=....
Can anyone ascertain why I get the error, described below? The query works in the Query Analyzer?? What am I doing incorrectly... Any assistance will be appreciated...
Thanks !
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim AccessionPresent, strsearchedfor, strsearchresult As String
Dim RcdCount As Integer
Dim ResultCount As Integer
AccessionPresent = Accession.Text
strsearchedfor = "The Keyed Accession Number "
strsearchresult = " Does Not Exist. Please Verify Your Entry. "
ErrorLabel.Text = String.Format("{1}<b><font size=ex-small color=003399>{0}</b></font>{2}", AccessionPresent, strsearchedfor, strsearchresult)
Dim MySQL As String
MySQL = "SELECT * FROM ClinicalSpecimen WHERE CAST(SpecimenID AS varchar(50))='" & AccessionPresent & "'"Dim objConnValidate As SqlConnection
Dim mySettingsValidate As New NameValueCollection
mySettingsValidate = AppSettings
Dim strConn As String
strConn = mySettingsValidate("connString")
objConnValidate = New SqlConnection(strConn)
MyCommand = New SqlDataAdapter(MySQL, strConn)
DS = New DataSet
MyCommand.Fill(DS, "SpecimenID")
RcdCount = DS.Tables("SpecimenID").Rows.Count.ToString()If DS.Tables(0).Rows.Count > 0 Then
Response.Redirect("Accession_Result.aspx?AccessionResult=" & AccessionPresent)
ElseIf DS.Tables(0).Rows.Count = 0 Then
Response.Redirect(http://www.aol.com)
IS CAUSING THE FOLLOWING ERROR:
Server Error in '/ClinicTest2' Application.
Syntax error converting the nvarchar value '3624-01' to a column of data type int.
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: Syntax error converting the nvarchar value '3624-01' to a column of data type int.
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:
I continue to have issues with SP-2 for SQL 2005 suite. It has now gotten so bad, I have multiple installations, including the TOOLS ONLY on my laptop failing, that I am going to stop ALL future installations of SP-2. The COM+ failures have not been resolved that I can determine. I have tried uninstalling, I have tried SP-1 before SP-2, every combination one can find. HELP.
Time: 05/07/2007 13:24:05.631 KB Number: KB921896 Machine: GA029-MDGRAVES OS Version: Microsoft Windows XP Professional Service Pack 2 (Build 2600) Package Language: 1033 (ENU) Package Platform: x86 Package SP Level: 2 Package Version: 3042 Command-line parameters specified: Cluster Installation: No
********************************************************************************** Prerequisites Check & Status SQLSupport: Passed
********************************************************************************** Products Detected Language Level Patch Level Platform Edition Setup Support Files ENU 9.00.1399.06 x86 SQL Server Native Client ENU 9.00.3042.00 x86 Client Components ENU RTM 9.00.1399.06 x86 STANDARD MSXML 6.0 Parser ENU 6.00.3883.8 x86 Backward Compatibility ENU 8.05.1054 x86
********************************************************************************** Processes Locking Files Process Name Feature Type User Name PID
********************************************************************************** Product Installation Status Product : Setup Support Files Product Version (Previous): 1399 Product Version (Final) : 3042 Status : Success Log File : C:Program FilesMicrosoft SQL Server90Setup BootstrapLOGHotfixRedist9_Hotfix_KB921896_SqlSupport.msi.log Error Number : 0 Error Description : ---------------------------------------------------------------------------------- Product : SQL Server Native Client Product Version (Previous): 3042 Product Version (Final) : Status : Not Selected Log File : Error Description : ---------------------------------------------------------------------------------- Product : Client Components Product Version (Previous): 1399 Product Version (Final) : Status : Failure Log File : C:Program FilesMicrosoft SQL Server90Setup BootstrapLOGHotfixSQLTools9_Hotfix_KB921896_sqlrun_tools.msp.log Error Number : 29549 Error Description : MSP Error: 29549 Failed to install and configure assemblies c:Program FilesMicrosoft SQL Server90NotificationServices9.0.242Binmicrosoft.sqlserver.notificationservices.dll in the COM+ catalog. Error: -2146233087 Error message: Unknown error 0x80131501 Error description: MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027) ---------------------------------------------------------------------------------- Product : MSXML 6.0 Parser Product Version (Previous): 3883 Product Version (Final) : 6.10.1129.0 Status : Success Log File : C:Program FilesMicrosoft SQL Server90Setup BootstrapLOGHotfixRedist9_Hotfix_KB921896_msxml6.msi.log Error Number : 0 Error Description : ---------------------------------------------------------------------------------- Product : Backward Compatibility Product Version (Previous): 1054 Product Version (Final) : 2004 Status : Success Log File : C:Program FilesMicrosoft SQL Server90Setup BootstrapLOGHotfixRedist9_Hotfix_KB921896_SQLServer2005_BC.msi.log Error Number : 0 Error Description : ----------------------------------------------------------------------------------
********************************************************************************** Summary One or more products failed to install, see above for details Exit Code Returned: 29549
I have a rather odd problem that hopefully you'll be able to shed some light on (nobody else has come up with anythig sensible).
We want to back up the databases to a hard drive held on another server so I mapped the drive in explorer to the drive then went into Enterprise manager and tried to create a backup device and it won't see the mapped drive.
I've tried mapping to my PC and I can see that via enterprise managers backup stuff (infact any PC in the office works) but it won't see any of the servers even though we can map to them and access them via windows explorer.
I've tried when logged on via sa and the windows NT administrator and still no luck. In fact no matter what I type or do it fails and keeps telling me device error or device off line which it isn't.
On our test instance of SQL Sever we can backup to other servers but not the new live version!
I have one report (R1) which includes a list of ports ("=Fields!Port_Name.Value")
Another report (R2) supplies details for individual reports and has a parameter named PortDWIDPortName which gets port names from the same dimension as those in R1. So in the field properties of the Port field in R1, I selected Navigation > Jump To Report and entered PortDWIDPortName = Fields!Port_Name.Value (also tried changing .Value to .Key or .UniqueName) but although it jumps to report R2 it does not enter a value for the parameter (ie leaves it blank or displays <Select Value> depending on whether multivalue or not).
Does anyone know the right syntax to pass the parameter ? If not, does anyone know to view what Jump To Parameter is returning so I can figure how to doctor it!
We currently have access to another department's SQL server. However they are taking that server offline within a few months, and we will need to migrate our data and DTS packages to a new solution before then. We have about 30 databases and 20 somewhat simple DTS packages, but only a few users need access. Funding is very tight.
SQL 2005's support of DTS is somewhat of a mystery to me. Docs state with 2000 Enterprise client tools installed + Express edition, that I can run DTS packages on Express edition. But the docs do not state the procedure for doing so, and I cannot register the Express server in the Enterprise manager(states must be using 2005 version of Enterprise manager). It seems I can Design a DTS package that resides on the 2000 server and specify a connection to the Express server, but the DTS package would not run, stating always that the table was in use, and I haven't explored it any further. May have just been a quirk.
I'm trying to conquer this in two pieces:
Cheapest solution for graphical design of DTS packages, or some techniology similar(I think I understand that this is called SSIS in 2005?). This would be needed by 1-4 users.
SQL 2005 Developer Edition for each user, only about $50 per user. MSDE for each user, but can this house DTS packages and be connected to by enterprise manager? Cheapest solution for data access and ability to run DTS packages by 2-10 users.
If SQL Express Edition is used to house data, can the DTS packages be distributed in some way that allows the users to run them? I.E. exported as VB code or some sort of file that can be loaded by an Access 2002 or VB.NET frontend. Can all users have Developer Edition or Desktop edition and run the DTS package from it, but have the DTS package connect to the Express Edition server where the data is housed? Or would this be a violation of what the Developer Edition is intended to be used for? Any other suggested scenarios are welcome.
Are we allowed to continue using the 2000 Enterprise manager after we no longer have access to a licensed SQL 2000 Enterprise server?
The feature comparison for the different 2005 editions doesn't mention DTS, but I know it works for some editions if the add on components are installed. I'm just not sure which versions support this.
I am having a little trouble with the CAST in my SELECT statement below. Any help is greatly appreciated.
SELECT group_id_ AS [Group ID], vendor_id_ AS [Vendor ID] , project_id_ [Project ID], resource_id_ [Resource ID], vendor_price_ [Old Price], new_price_ [New Price], (CAST (new_price_/vendor_price_)-1 AS DECIMAL (4, 2)) AS [Difference] FROM hbs_vnpq WHERE (group_id_ = '210') AND (vendor_id_ = '08416') AND (new_price_ >0) AND (vendor_price_ >0) ORDER BY [Difference]
Server: Msg 1035, Level 15, State 10, Line 7 Incorrect syntax near 'CAST', expected 'AS'.
im doing a sum on a table and it either returns a number in decimal format or 'null' . The problem is when it returns null i want it to just make the text say '0.00'. So i did a test on the object that if it returns NULL just print '0.00' but if it is not null it tells me that there is a number there and i want to store that as a decimal and print it out. But i get an error for a type cast when im not it should not even be going to that part of the code. In the code below the first executescaler will return null so it should just go straight to the else. But it gives me the type cast error in the if that shouldnt be seen. The error and code are below. //Borrower NSF FEES cmd.CommandText = "select sum(itemamount) from postmtdtls where loanid='" + LoanID + "' and Transactioncode = '310'"; object temp = cmd.ExecuteScalar(); if (temp != null) { decimal B_NSFFees = ((decimal)cmd.ExecuteScalar()); borrowerPayoff_NSFFees.Text = String.Format("{0:#,#.##}", B_NSFFees).ToString(); //Borrower NSF FEES } else { borrowerPayoff_NSFFees.Text = "0.00"; //borrowerPayoff_NSFFees.Text = "0.00"; } Server Error in '/WebSite5' Application. Specified cast is not valid. 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.InvalidCastException: Specified cast is not valid.Source Error: Line 774: if (temp != null) Line 775: { Line 776: decimal B_NSFFees = ((decimal)cmd.ExecuteScalar()); Line 777: borrowerPayoff_NSFFees.Text = String.Format("{0:#,#.##}", B_NSFFees).ToString(); //Borrower NSF FEES Line 778: }Source File: c:ProgrammingFilesWebSite5InvestorPool.aspx.cs Line: 776 Stack Trace: [InvalidCastException: Specified cast is not valid.] InvestorPool.GetLoanInfo(String LoanID) in c:ProgrammingFilesWebSite5InvestorPool.aspx.cs:776 InvestorPool.MortAccountText(Object sender, EventArgs e) in c:ProgrammingFilesWebSite5InvestorPool.aspx.cs:660 System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +75 System.Web.UI.WebControls.TextBox.RaisePostDataChangedEvent() +124 System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +7 System.Web.UI.Page.RaiseChangedEvents() +138 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4507 Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
I am pretty new to SQL for SQL Server 2005. In a view I have a column CAST(Field1 as int). Field1 is a varchar.All works well except when the data is not numeric such as a '?' or '*'.How can I get around this, with a case statement, coalese?I only want to perform the CAST on valid numeric values.The valid values in the varchar field are blank, null,'0','1','2','3','4','5','?','*' and maybe othersThanks
If I run the following query in SQL Server Management Studio it returns the correct results: (Searching the table for the field "SpecimenID (an INT)" against the data entered (a Text Field - "7575-01") from the submitted form. SELECT ClinicalID, SpecimenID, PatientID, LabID, Accession, Bacillus, Francisella, Yersinia, Brucella, Burkholderia, Coxiella, Staphylococcus, Other, OtherExplanation, CollectionDate, strddlTransportMedium, strddlSpecimenSource, UserName, Test, SpecimenCount, DateAndTimeFROM ClinicalSpecimenWHERE (SpecimenID = CAST('7575-01' AS VARCHAR(50)))ORDER BY SpecimenID DESCHowever, when I try to use the same logic in the ASPX.VB code behind page, as follows below, I either get an error message (Syntax error converting the varchar value '' to a column of data type int.) or record not found.... Can someone please explain what I am missing here.... MySQL = "SELECT * FROM ClinicalSpecimen WHERE SpecimenID = CAST(('" & AccessionPresent & "') AS VARCHAR(50))" *"AccessionPresent" is the value of the text field retrieved from the form. I guess what I am really asking is how can I search for an INT value in a table using a VARCHAR Field. Thank you for any or all assistance !!!
Hi over there,I hope this question is not too simple, but I didn't manage to figure out why...I would need an explanation for following issue:I'm reading data from a database (MSSQL) and it the column "PersonBirthday" is DBNull.I wanted to prevent the error (Textbox.Text = DBNull) with an IIF. The thing is I get thistypecast exception:"Conversion from type 'DBNull' to type 'Date' is not valid." This code is NOT working, why? txtPersonBirthday.Text = IIf(IsDBNull(.Item("PersonBirthday")) = True, String.Empty, CDate(.Item("PersonBirthday")).ToString("yyyy-MM-dd")) When I'm using this code, which is for me obviously the same, just with an if-block it works,and I want to know why - please explain. If IsDBNull(.Item("PersonBirthday")) Then txtPersonBirthday.Text = String.Empty Else txtPersonBirthday.Text = CDate(.Item("PersonBirthday")).ToString("yyyy-MM-dd") End IfThanks in advance,cheers,uquandux If IsDBNull(.Item("PersonBirthday")) Then txtPersonBirthday.Text = String.Empty Else txtPersonBirthday.Text = CDate(.Item("PersonBirthday")).ToString("yyyy-MM-dd") End If
Can't seem to find why I'm getting this error: Specified cast is not valid. Ok, using a stored procedure for SQL Server 2000 and here is the main part of it: SELECT id, rank, firstName, lastName, service, status, createdTime FROM accessRequest WHERE lastName LIKE @tLastName AND firstName LIKE @tFirstName And the C# code behind from the class file: SqlDataReader spResults; conn.Open(); spResults = command.ExecuteReader(); while( spResults.Read() ) { AccessRequestSearch request = new AccessRequestSearch( (int)spResults.GetInt32( 0 ), spResults.GetString( 2 ), spResults.GetString( 3 ), spResults.GetString( 1 ), spResults.GetString( 4 ), spResults.GetString( 5 ), Convert.ToDateTime(spResults.GetString( 6 ))); searchResults.Add( request ); // Add to Array List } spResults.Close(); The part in red is where I think it's happening because that is what I just added to the request. createdTime in the table is set as DateTime. Can anyone see what I am missing here? More info is available if needed. Thanks, Zath
I have a table with a column called Sample_Date_and_Teime with a row definition of char(16). What is stored in this table is a date (ie. 1020621141517000) The first char is the century, the next are the year, the next two are the month, the next two are the day, the next 2 the hour, the next two are the minutes, and the next 2 are the seconds and the last 3 are to be ignored... what I need to do is write a select statement that converts this column into a datetime so that I can then do a insert into a new table by selecting from this table based on a date range. PLEASE HELP:confused: :confused: :confused:
I use to import data from DBF Clipper databases into SQL Server. When a table is just imported its date fields have string format. I need to copy their data to tables of database where they ahve to be converted into date. Direct operator INSERT doesn't convert properly (I've not successed in changing default date format so it'll be covertable) but using CAST I can get result of strings like 13.05.1970 0:00:00 as datetime type. But not all records can be coverted this way. For ones can't be converted I've solved to make NULL fields there. But I don't know how to make CAST operation return NULL when convertion isn't possible. The query INSERT INTO people_temp (reg_num, surname, stname, patronymic, foreing, gender, birthdate, fam_pos, dwell_type, children, nation, par_not, region, stud_fml, parn_fml, com_prob, sp_prob, sn_passport, nn_passport, dv_passport, wg_passport) SELECT STUDENTs_temp.REG_NOM, STUDENTs_temp.FAMILY, STUDENTs_temp.NAME, STUDENTs_temp.PARN_NAME, STUDENTs_temp.INOSTR,
STUDENTs_temp.SEX, CAST(PSPR_temp.DATA_BORN AS smalldatetime), PSPR_temp.SEM_POL, PSPR_temp.XAR_JT, PSPR_temp.CHILDREN,
PSPR_temp.NATION, PSPR_temp.SV_ROD1 + PSPR_temp.SV_ROD2 AS Expr1, PSPR_temp.REGION, PSPR_temp.STUD_FML,
PSPR_temp.PARN_FML, PSPR_temp.OB_STAJ, PSPR_temp.SP_STAJ, PSPR_temp.SN_PASPORT, PSPR_temp.NN_PASPORT, PSPR_temp.DV_PASPORT, PSPR_temp.WG_PASPORT FROM STUDENTs_temp INNER JOIN PSPR_temp ON STUDENTs_temp.REG_NOM = PSPR_temp.REG_NOM gets an error 'The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value'. Tell me please how can make type casting return NULL if convertion isn't possible.
Have the following in my SELECT statement, which I'm having issues with when I modify it to include a CAST or a CONVERT.
CONCAT(PER.[PERSON-REF],ROW_NUMBER() OVER (PARTITION BY PER.[PERSON-REF] ORDER BY TEN.[tenancy-ref])) AS 'ID'How do I convert or cast it to a varchar (20)?
I found this nifty code on stackoverflow that works well but I'm trying to send the results to a text file and the column lengths are huge. I used CAST for the first line and it worked great but I can't seem to make it work with duration. Here's the original code:
I have a quick question. created a report with this formula below. It works when I put a date range from 1-1-2007 to 2-1-2007, but when I put in a date range of 03-01-2008 through 03-31-2008. i get an error message of arithmetic overflow error converting numeric to data type numberic.
So instead of haveing the formula below be (4,2) I put it as (5,2) and now it work. Why is that?
CAST(clm_sppo / clm_tchg * 100 AS decimal(4, 2)) AS PercentSavings
I have a problem with casting a string number to int. for exmaple i have the number '0110' (string) and i would like it to be 110. or '0001' to be 1. i tried to do: cast(MyNUM as int) . but i get "Syntax error converting the nvarchar value 'O322' to a column of data type int."
I have a table with the following structure: Table: Meeting ID integer not null Desc text null
Here Col 'Desc' is a text type stores description. I have used the following UPDATE query: UPDATE Meeting SET Desc='New Updated text......' + ' ' + CAST(Desc as varchar) WHERE ID=100
Issues: 1. Since i did'nt specify lenth for varchar it takes only 30 chars from existing value and added to the edited text. 2. If i give like this CAST(Desc as varchar(8000)); it might take only first 8000 chars; remaining would be truncated correct? I assume that will happen. 3. If i don't use CAST i get error msg: "Invalid operator for type.." Is there any work around in this situation? or better way to do it.
Hi, I'm very new to SQL. Trying to sum two fields, but I have to change the datatype first. Here's the code and the error message I receive. Any help would be appreciated.
SELECT TS_RESPONSIBLE, TS_STATUS, TS_USER_07, SUM(TS_USER_07 * TS_STATUS) AS value FROM TEST_54_VW GROUP BY TS_RESPONSIBLE, TS_STATUS, TS_USER_07 WHERE CAST(TS_USER_07 AS INTEGER)
I am using MS-Access as a front end for my MS-SQL DB. I have a sql view thatuses the following:SELECT TOP 100 PERCENT RECID, PATNUMBER AS [PAT #], SVCCODE AS [ServiceCode], QTY, PROF_CHRGS AS [Pro Fee's'], AMOUNT,BILLDATE AS [Bill Date], CHKAMT AS [Check Amt], PSDATEAS [Service Date], POSTDATE AS [Post Date], TRNSCODE AS [T Code],TRLR AS [T Code Desc], SUBSTRING(CAST(SVCCODE ASvarchar), 1, 4) AS [Dept #]FROM dbo.PAT_TransactionsORDER BY PATNUMBER, SVCCODEMy problem is the cast command. Will this sql view works and cast theSVCCODE field into a varchar, I need to cast the reseult of this,SUBSTRING(CAST(SVCCODE AS varchar), 1, 4) AS [Dept #], back in to a decimalformat. I am dropping this view onto a form and need to link to a field onthe form that is in decimal format.The only way I could get this to work was to create another view, based onthe one above, and cast the [Dept #] field back into the decimal format. Isthere any better way to do this? Can I nest the Cast command?Hope this makes sense.Thanks in advance.Mikem charney at dunlap hospital dot org
i have looked at several guides, and have come up with some code, although for some reason i am unable to get it to work, and receive an error:
Msg 6260, Level 16, State 1, Line 1 An error occurred while getting new row from user defined Table Valued Function : System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Object[]'. System.InvalidCastException: at UserDefinedFunctions.FillRow(Object obj, String& PID) .
Below is my code: using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server;
using System.Collections;
public partial class UserDefinedFunctions { const string SELECT = @"SELECT pointData.PID FROM pointData INNER JOIN pointDevices ON pointData.PID = pointDevices.PID WHERE pointDevices.UUID = @UUID AND DATEADDED >= @DATE_START AND DATEADDED <= @DATE_STOP ORDER BY DATEADDED";
I'm trying to cast the variable Alumni and keep getting a "The type of the value being assigned to variable "User:: Alumni" differs from the current variable type" error. The resultset from Records is a varchar(max) and the variable Alumni is a string. I found a blog that says to cast the result column to a max size limit. I want to do it this way so I can put the result in the message of a send mail task.
Here is the blog. http://blogs.conchango.com/stevewright/archive/2006/01/20/2686.aspx
SELECT Records as Alumni
this doesn't work or I dont' have the syntax right? SELECT Records as CAST(Alumni as varchar(max))