How To Cast The Value In C# Resulted From Max() Command In SQL Server Developer
Aug 1, 2007
Could anyone help of how to cast the value in C# resulted from max() command. To complicate the matter, from the query result I see in the Microsoft SQL Server Management Studio, if there are records the value is number. But if there are no records, the value is NULL. How do I handle these two possible different conditions?
I have tried:
- string test = (string)reader["MaxOrderID"];
- int test = Convert.ToInt32((string)reader["MaxOrderID"]);
- string test = Convert.ToInt32(reader["MaxOrderID"]).ToString();
all failed. And what do I do if the value is NULL. And also how do I do to cope with these two different possible conditions?
For example, I have the following code:command.CommandText = "Select max(OrderID) as 'MaxOrderID' from [Order]";command.CommandType = CommandType.Text;
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
How to launch Oracle SQL Developer through "Run" window in windows as we can launch SQL Server Management studio through "Run" command line using command line "sqlwb -S localhost -d MyDB -U sa -P
Dear Experts,Ok, I hate to ask such a seemingly dumb question, but I'vealready spent far too much time on this. More that Iwould care to admit.In Sql server, how do I simply change a character into a number??????In Oracle, it is:select to_number(20.55)from dualTO_NUMBER(20.55)----------------20.55And we are on with our lives.In sql server, using the Northwinds database:SELECTr.regionid,STR(r.regionid,7,2) as a_string,CONVERT(numeric, STR(r.regionid,7,2)) as a_number,cast ( STR(r.regionid) as int ) as cast_to_numberFROM REGION R1 1.00112 2.00223 3.00334 4.0044SELECTr.regionid,STR(r.regionid,7,2) as a_string,CONVERT(numeric, STR(r.regionid,7,2) ) as a_number,cast (STR(r.regionid,7,2) as numeric ) as cast_to_numberFROM REGION R1 1.00112 2.00223 3.00334 4.0044Str converts from number to string in one motion.Isn't there a simple function in Sql Server to convertfrom string to number?What is the secret?Thanks
There are conflicting postings everywhere about this. I built a small site using VWD and SQL Server Express, but need to convert to Sql Server 2005 Developer because the DB will exceed 4Gb. Tried to install and could not connect or use from VWD. Tried to uninstall, got into large mess with the byzantine uninstall process, and have now started with a clean machine.
I installed SQL Server 2005 Developer first, then installed VWD Express 2008 without installing SQL Server Express. VWD won't let me connect to an existing database, won't let me add a new database and doesn't even show the Database Tools option under the Tools menu.
Is there someone with specific knowledge that can provide any enlightenment? Would be much appreciated.
I am working on adding DBs to the AG but for some reason I am getting this error.
"Joining DB on secondary replica resulted in error"
Msg: The remote copy of the database is not recovered far enough to enable DB mirroring or to join AG. Missing log records have to be applied to the remote DB by restoring the current log backups" Which I did. I took the log backup of DB1, restored it on DB2 with no recovery, but still I am getting the same error.
I have problem to execute query with interval date.
If try this query I don't have problem and the output is correct:
SELECT * FROM dotable WHERE dotableDate BETWEEN CONVERT (datetime, '01/01/2015', 121) AND CONVERT (datetime, '09/01/2015', 121);Instead if try this I have error: SELECT * FROM dotable WHERE dotableDate BETWEEN CONVERT (datetime, '25/01/2015', 121) AND CONVERT (datetime, '28/01/2015', 121);
[Err] 22007 - [SQL Server]The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
We've been using SQL Server 2005 for a while as the db for our web app. Everything has been working fine, until yesterday when we started getting a "Arithmetic operation resulted in an overflow. (System.Data)" error message when trying to connect from SQL Server Management Studio or from our web app. This only happens when trying to connect remotely, although remote connections have worked for us perfectly in the past. The full error message is reproduced below. Thanks ahead of time for any help. ===================================Cannot connect to serverName===================================Arithmetic operation resulted in an overflow. (System.Data)------------------------------Program Location: at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean& marsCapable) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection(UIConnectionInfo ci, IServerType server) at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()
Can someone here confirm or deny that Visual Web Developer 2005 Express Edition doesn't work with SQL Server Developer Edition 2005?
I was about to order SQL Server Developer Edition 2005 on Amazon, to use with Visual Web Developer 2005 Express, when I read a user comment that the two are incompatible with each other. Does anyone know for sure if that is true?
What I'm wanting to do is develop an ASP.NET web application on a web host using a SQL Server database. I use VS2003 and SQL Server Enterprise 2000 at work, but I'd like to learn the 2005 editions for this side project. I don't own any of the developer tools/IDEs personally, so I'm trying to find the most affordable way to do this for my home business.
Hello all. I'm giving serious thought on changing gears withing the IT world. For several years I have been a software developer who has been fortunate enough to have been involved in the needed databases. From just sketching out tables for the DBA to doing the database from the ground up and maintaining it during production. Along the way I've known that I didn't do as quality of a job as a knowledgeable DBA would do but given the situations I made do just fine.
I am considering switching gears to the database side only, coding as secondary. Since I am basically familier with most aspects of SQL Server in a general way, I am looking to take that knowledge and become a "Professional". What I am looking for is a few books to help out. Maybe a "Become a DBA for Software Developers" or something. I know that mining these and other forums are very valuble but I'd like some other training materials as well.
Have I been clear enough on what I am looking for? I don't quite feel like I have.
Basically, what would you recommend for a good software developer who is looking on switching to becoming a good database person?
I'd like to stay in SQL Server for now, since that is what they use here and it would give me an opportunity to practice.
Also, do you see value in the studying process for certifications in this area?
I can't tell if the SQL Developer install upgraded the service, but left the SqlExpress version information, or if I'm still really only using SqlExpress.
Also, my intended target is SQL Enterprise, so if I am using SQL Express am I asking for trouble when I go to move the database over? Are the database formats compatible?
I've poked around trying to search for this answer for a while and haven't turned anything up. Maybe I'm searching on the wrong terms...
i get this error when running this sp: i think i should use convert method but how? Msg 296, Level 16, State 3, Procedure CmmSPNet_userAlbumPhotos, Line 7 The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'CmmSPNet_userAlbumPhotos' AND type = 'P')DROP PROCEDURE CmmSPNet_userAlbumPhotos GOCREATE PROCEDURE [CmmSPNet_userAlbumPhotos] @albumID int, @orderBy varchar(100), @orderDirection varchar(4)AS SELECT ID,UserID,Photo,ALbumID,Title,views,date_added from cmmNet_userAlbumPic where albumID=@albumID order by case @orderBywhen 'date_added' then case @orderDirection when 'desc' then '31-dec-10' - date_added /* highest date value */else date_added endwhen 'views' then case @orderDirection when 'desc' then 21474 - [views] /* highest integer value */else [views] end else date_added end GO
my date_Join is 8char as it is datetime in microsoft sql. cant change to more. when i type the date 2007-12-12. it says Arithmetic operation resulted in an overflow.
Scenario:----------SQL server: 192.168.1.3Server 2: 192.168.1.2, a folder named ABC is shared out.Both servers have the same password for the account named"Administrator"----------i tried to execute the following command in SQL server (192.168.1.3):exec master..xp_cmdshell 'move /Y "D: est.txt""\192.168.1.2ABC est.txt"'and got the error "access is denied"However, when i execute the move command in the command prompt of theSQL server, there was no problem. i'm able to connect to\192.168.1.2ABC without any problem too.What could be the problem?
I have a bit of a problem I haven't come across before. I was testing some restore code using smo, when the restore process got corrupted. Now I cannot log into that database file. Whenever I try and connect to it, I get a login error. Connections to this database file previoulsy worked very well.
I do not get login errors for databases with different names, or when using the same database file on another computer. There must be some data stored somewhere that is causing this. I have removed the database file and reloaded it, but to no avail. Any insight into this would be appreciated
i run a sql command like this select * from table_name what i want is that if no. of records found are greater then 500 than it should stop the query and only show those 500 records dont go further and stop the process waiting for reply ashish bhatnagar
When running a query such as this on a database view:
select count(*) from WWALMDB.dbo.v_AlarmEventHistory2
SQL throws the following error:
The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
Oddly on a Table the count(*) function works.
Is there a limit on views or the count(*) function that I am not aware of?
How do I use the CAST or CONVERT function in the code below, I require a third column (named Diff) which Minus the StartTime from the EndTime and the result is outputted in the third column (named Diff).
Calculation: @Diff = (@EndTime - @StartTime)
I still want the variables (@StartTime and @EndTime) to remain as nvarchar.
The code:
DECLARE @StartTime nvarchar(10) = '12:10'; DECLARE @EndTime nvarchar(10) = '12:30'; DECLARE @Diff time(1) = '00:00'; SELECT @StartTime AS '@StartTime', @EndTime AS '@EndTimes', @Diff AS '@Diff';
Hi,I used SQL Server 2000 Personal Edition. I created a stored procedurehaving input parameters as smallint,tinyint,char,varchar andsmalldatetime. When I executed it by Query Analyzer, it's ok. But whenI executed it by ASP code that used ADODB.command, it showed error:Invalid character value for cast specification .Though SQL Server debugger, it showed:[Microsoft][ODBC SQL Server Driver]Invalid character value for castspecificationWhat did I do wrong? How do I fix this problem?TIAKrungPS: One of input parameters was smalldatetime, but I casting it in ASPas date as:Const adDate=7datetxt='2004/6/28'cmd.Parameters.Append cmd.CreateParameter("CoopId",adChar,adParamInput, 8, coopid)cmd.Parameters.Append cmd.CreateParameter("Addr",adVarChar,adParamInput, 100, addr)...cmd.Parameters.Append cmd.CreateParameter("Cdate",adDate,adParamInput, , datetxt)....cmd.execute
While doing performance testing on a Tomcat based web application using the v1.1 JDBC driver connecting to SQL Server 2005, the tomcat server has been throwing the above exception at a fairly low rate. I have seen some related issues in the forums with v1.1 of the MS JDBC driver, but those were asking about connection reset related errors. In this case the 'invalid packet header' exception is consistently seen. I am in the process of repeating the test with some additional application side logging turned on, and have tried enabling FINEST level logging for the driver, but that leaves me with a 500MB log file and so far no instances of that exception in question being thrown. This is not unusual, the error has only been seen about 14 times in about 20 tests, with each test running about an hour and a half.
A few quick tests with the 1.2 driver did not throw this exception, but did throw a high number of '[Connection|Statement|Resultset] Closed'
While I gather more information, I was wondering if there is anything significant in this particular exception type that could point to a more specific set of tests I could run?
The exceptions seen so far:
Exception #1:
java.lang.NullPointerException at com.microsoft.sqlserver.jdbc.DBComms.receive(Unknown Source) at com.microsoft.sqlserver.jdbc.DBComms.receive(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerStatement.doCloseServerCursor(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerStatement$CloseServerCursorRequest.execute(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerStatement.closeServerCursor(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerResultSet.close(Unknown Source) at com.X.db.CSInternalDB.close(CSInternalDB.java:950) at com.X.db.CSQuery.close(CSQuery.java:169) at com.X.container.ContainerManager.getFolderContent(ContainerManager.java:1313) at com.X.container.ContainerCommands.getContent(ContainerCommands.java:1086) at com.X.container.ContainerCommands.execCommand(ContainerCommands.java:192) at com.X.BaseHandler.getObjectFromDoc(BaseHandler.java:169) at com.X.BaseHandler.processDOM(BaseHandler.java:284) at com.X.Dispatcher.execIt(Dispatcher.java:546) at com.X.Dispatcher.execCommand(Dispatcher.java:333) at com.X.BaseHandler.getObjectFromDoc(BaseHandler.java:169) at com.X.X.execute(X.java:600) at com.X.HttpReceiver.doRequest(HttpReceiver.java:275) at com.X.HttpReceiver.doGet(HttpReceiver.java:181) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.cluster.tcp.ReplicationValve.invoke(ReplicationValve.java:346) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Unknown Source)
#2:
java.sql.SQLException: The DBComms.receive operation resulted in an invalid packet header type:-86. PktNum:0. nReceived:8. at com.X.db.CSPreparedStatement.executeQuery(CSPreparedStatement.java:474) at com.X.db.CSAnalyzer.executeQuery(CSAnalyzer.java:485) at com.X.db.CSQuery.sqlPrepareExecute(CSQuery.java:559) at com.X.form.FormManager.getInternalFormProps(FormManager.java:1803) at com.X.form.FormManager.getInternalFormProps(FormManager.java:1762) at com.X.route.RoutingCommands.genericPrepareRoutingPage(RoutingCommands.java:5618) at com.X.route.RoutingCommands.prepareRoutingPage(RoutingCommands.java:3899) at sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.X.iplugin.DynamicCommandMethod.execute(DynamicCommandMethod.java:35) at com.X.route.RoutingCommands.execCommand(RoutingCommands.java:209) at com.X.BaseHandler.getObjectFromDoc(BaseHandler.java:169) at com.X.BaseHandler.processDOM(BaseHandler.java:284) at com.X.Dispatcher.execIt(Dispatcher.java:546) at com.X.Dispatcher.execCommand(Dispatcher.java:333) at com.X.BaseHandler.getObjectFromDoc(BaseHandler.java:169) at com.X.X.execute(X.java:600) at com.X.HttpReceiver.doRequest(HttpReceiver.java:275) at com.X.HttpReceiver.doGet(HttpReceiver.java:181) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.cluster.tcp.ReplicationValve.invoke(ReplicationValve.java:346) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Unknown Source)
Anyone encounter differences between SQL2K EE and SQL2K Dev Editon?FAILS-----Machine_A [App Server] <-- JDBC --> Machine_ASQL2K_Dev_Ed..dbError: "com.inet.tds.SQLException: Connection refused"When app server on Machine_A attempts to connect to database onMachine_A the conenction is refused.SUCCEEDS---------Machine_A [App Server] <-- JDBC --> Machine_BSQL2K_EE..dbWhen app server on Machine_A attempts to connect to database onMachine_B the conenction succeeds and the app server runs normally.JDBC driver: com.inet.tds.TdsDriverjdbc:inetdae7:locahost:1433I don't believe the app server is exhausting the 10-connection max onSQL2K developer edition (there is a 10-connection limit imposed on thedeveloper edition, correct?)LB
I found that when I install MSDE, then I can create/edit database objects for MSDE database in Visual Studio 2003 Server Explorer, but when I try to create/edit database objects under the default database created by the SQL Server 2000 installation, I cannot do these tasks as no option for these tasks appear when I right-click on the database object in Server Explorer. Anyone knows why this is happening?
Hello,This is hopefully just a quick question. I'm looking to re-jig our in-house development infrastructure and part of that will be some sort of SQL Server product, and I'm hoping it will be the Developer edition.My question is, how many copies of the Developer edition would I need to purchase, if I have one Windows 2003 server (which will server the databases) and two client machines which will use it.My initial thought is 2 copies, one for each user (as the license states). But what about the server? Do I just install one of the two copies onto the server and the license covers the two client connections?This might seem a silly question with an obvious answer to you guys. However, am I right? I just need to get this clear in my head.Thanks in advance..
I am looking for a detailed tutorial that explains how to set-up merge replication services for a major project. I have seen all of the claims that SQL Mobile Server 2005 is able to connect to a merge publication with SQL Server 2000. However, where are the tutorials? I must have a proof of concept in a few days to quote this project. Can anybody help with this issue? Thanks!
I'm trying to register a developer's 2000 pc from my 2005 pc.
i'm not sure this is even something possible from Dev Edition to Dev Edition- I can register a 2000 server just fine.
I can ping him. Both our systems have remote access 'on'. His server is (local), i've tried connecting to it by just entering his machine name and by using just the ip address. The error I get is "timeout expired. The timeout elapsed prior to completion of the operation or the server is not responding."
Am I just not registering this properly? I entered just the ip address in the 'server' box. I am connecting as sa with the pw he gave me. When i connect to my server, I use the ip addressinstance. However, I am not sure what to use for the instance when all I see when I look at his machine is (local).
I have a home network that has 2 XP Pro machines on it. Can you use a SQL server 2005 DB remotely? I have the management tool on the machine that has VS 2005 but when I try to connect to SQL server I get an error. 'A connectiopn was established with the server but an error occurred during the pre-login handshake. This failure may be caused by the fact that under the default settings sQL server does not allow rempte connections (provider:named PipesProvider, err=0) I would like to store the data on the server on a different machine -- can this be done using the home/small office network?
Hey, Im trying to make a website that I can enter information on the website and have it transfered to the database the problem is the website and database are on two different computers , how do I copy the data base onto the other computer and have it will be ready to take information from the website and store it in the database?
I am a developer in need of setting up a SQL Server test environment for many users.
Can the Dev Edition be used as a back-end to handle this type of testing? Are my limited to one connection from my development machine?
As you can tell, <sarcastic tone>i am having a real fun time with this one</sarcastic tone>. Licensing terms are an area that i tried but sometimes cann't stay out of.
My employer recently purchased an MSDN subscription for each developer in our group. I sort of feel like a kid in toy store. I do not know what to play with first. Anyways. I have noticed there are several versions of SQL Server 2000. Enterprise, Personal and Developer. I undestand the difference between Enterprise and Personal Editions, but I do not know what make Developer different. Does any one know?