Posts

Time Format in SQL

Image
Today I received a question from a guy on SQL title, I'm not a SQL guy, but when I dive to solve this, done. Look at the question:- { SELECT LEFT(CONVERT(VARCHAR, online_time,109),4)+' '+ right(convert(varchar, online_time,109),2) as online_time from time above is my query i want output as 04:30 am  4:30 am will do(if initial 0 is removed no prob) 09:45 pm 11:15 am my prob is that above query is giving right output for time before 10 am/pm but after 9:59 am/pm time is wrong i.e, it displays 11:3 pm instead of 11:30 pm and give right for 4:40 pm how i can do that } Now, look at my solution:- SELECT SUBSTRING(CONVERT(CHAR(26), GETDATE(), 9), 12, 6) GO --OUTPUT = 11:30 and if you want to add AM or PM then SELECT SUBSTRING(CONVERT(CHAR(26), GETDATE(), 9), 12, 6) + ' ' + SUBSTRING(CONVERT(CHAR(26), GETDATE(), 9), 25, 2) COLNAME GO --OUTPUT = 11:30 AM Please Note: At the place of ' '

A network-related or instance-specific error occurred while establishing a connection to SQL Server

Image
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server) In this post I am going to show you the way to overcome this issue. Just follow the quick steps: (i) Open SQL Server Configuration Manager (ii) Start the selected services as given in image below. In most cases these steps will fix your issue. Thanks.

Time Out to Connect SQL Server Issue

When performing tasks involving a large amount of data in Ultimate Survey Enterprise survey software via your web browser, an error is thrown that looks similar to the following: 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.OleDb.OleDbException: Timeout expired Solution: 1. Open SQL Server Enterprise Manager and find the server that contains your Ultimate Survey Enterprise survey software database. 2. Right click on the server name. 3. Select properties. 4. Choose the Connections tab. 5. Increase the query timeout value. The value is in seconds. Set it to 0 for unlimited time 6. Click OK.

Database 'compuzitdb1' cannot be opened due to inaccessible files or insufficient memory or disk space

Today in the morning when I tried to access my one of the website it displayed titled error. I got socked that why this error coming up. The reason was my Database Host Provider where changed the server and he missed something to activate for my database and this causes the error "Database 'compuzitdb1' cannot be opened due to inaccessible files or insufficient memory or disk space" . When I contacted to DB experts they told me to be relax because it is a normal DB error and can be fixed by trying the following checks. 1) If possible add more hard drive space either by removing of unnecessary files from hard drive or add new hard drive with larger size. 2) Check if the database is set to Autogrow on. 3) Check if the account which is trying to access the database has enough permission to perform operation. 4) Make sure that .mdf and .ldf file are not marked as read only on operating system file system level. I hope this post will help you t

Database Not Available Error in Oracle

To fix this error: (i) Click on Start > Run > Type 'cmd' and press enter (ii) Now type 'svrmgrl' and press enter (iii) Type 'connect' and press enter (iv) Type Username 'internal' and password 'oracle' and press enter (v) Type 'startup' and press enter (vi) Now it will take about 1min to process and finally click 'edit' to close cmd Now start PLSQL, you error is fixed.

Oracle Package

Basically packages is set of procedures, functions, cursors, constraints and exceptions in one unit. To execute the package we write the code as follows: EXECUTE SALARY_PACKAGE.NEW_WORKER('MICE'); In above example SALARY_PACKAGE is package name and NEW_WORKER is procedure name. Creating Package To create package user should have the CREATE PROCEDURE privilege. Two create package two techniques have to be done separetly: (i) Creating package specification A package specification includes list of functions, procedures, variables, constraints,  cursors nd exceptions and will be available for package body. CREATE OR REPLACE PACKAGE <NAME> ------- ------- Above code should be saved in saperate file with saperate name. (ii) Creating package body The name of package body should be equal to name of package specification but file name should be different than above file name.  CREATE OR REPLACE PACKAGE BODY <NAME> -------

Oracle Methods

Method is block of PL/SQL code used to encapsulate the data access method for an object, it is also specified as part of the abstract datatype specification as (CREATE OR REPLACE TYPE  MARKS_TY AS OBJECT) and their body declaration as (CREATE OR REPLACE TYPE BODY MARKS_TY AS MEMBER FUNCTION TOTMARKS()). Before to learn methods it is recommanded to get overview the abstract datatype teqniques.  Creating specification CREATE OR REPLACE TYPE MARKS_TY AS OBJECT (M1 NUMBER(3), M2 NUMBER(3), M3 NUMBER(3), MEMBER FUNCTION TOTMARKS(M1 IN NUMBER, M2 IN NUMBER, M3 IN NUMBER) RETURN NUMBER); In above example, TOTMARKS is declaration of function which will be used later in function calling to get defined.  Defining function (body declaration) CREATE OR REPLACE TYPE BODY MARKS_TY AS MEMBER FUNCTION TOTMARKS(M1 NUMBER, M2 NUMBER, M3 NUMBER) RETURN NUMBER  IS  BEGIN RETURN(M1+M2+M3); END; END; / Creating table using above abstract datatype MARKS_TY CREATE TA

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples