I am facing a funny problem. I am doing a select to get records with "ExitDate" greater than "FromDate". However, when I run the query, it is also returning the "FromDate".
SET @FromDate = '3/31/2000' SELECT IndividualID, ExitDate FROM clientserviceprogram WHERE exitdate IS not null AND EXITDATE > @FromDate
I am still getting records with ExitDate = '3/31/2000'.
Although I am familiar with SQL commands I have never worked with SQL server before and find myself at a loss for which direction to take. I have a database for equipment reservations. I need to write a procedure to notify the end-user if a specific piece of equipment is already checked out during the time frame requested. I'm reading up on stored procedures and triggers and not sure which one (if either) is appropriate to use. Any suggestions? Thanks,
Just want to check if my query is the standard way to check if date ranges overlap in a price table as I need to check any that overlap as I can't have two prices on one day.
For example if in a table there was:
Product TROUSER Colour BLUE Start Date 01-NOV-13 End Date 20-NOV-13 Price £20.00 Start Date 10-NOV-13 End Date 12-NOV-13 Price £18.00 Start Date 21-NOV-13 End Date 25-NOV-13 Price £15.00
The top two overlap.I'm doing this which is giving me nothing returned which I'm hoping means I have no overlapping date ranges:
I am new to SQL developement ( am .Net developer). I need to implement a stored proc in sql 2005 on CC expiration task.
I have CC exiration date. By using expiration date (like '01/08'),
Conditions are:
1. If CC expiring within 31 days. Stored proc will write the Customer data in EmailNotification table with message type =1. (Customer will not get second notification until 14 days before expiring)
2. If CC expiring within 14 days. Stored proc will write the customer data in EmailNotification table with message type =2. (Customer will not get second notification until 11 days before expiring)
3. If CC expiring within 11 days. Stored proc will write the customer data in EmailNotification table with message type =3. (Customer will not get second notification until 2 days before expiring)
4. If CC expiring within 2 days. Stored proc will write the customer data in EmailNotification table with message type and update orderStatusID to On Hold CC Expired in order table.
My Tables are
1.
TABLE [dbo].[Order]( [OrderID] [int] IDENTITY(1,1) NOT NULL, [CustomerID] [int] NOT NULL, [CustomerCode] [nvarchar](12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [DateCreated] [datetime] NOT NULL, [DateOrdered] [datetime] NOT NULL, [OrderTypeID] [int] NULL, [OrderStatusID] [int] NULL, [LastProcessDate] [datetime] NULL,
2. CREATE TABLE [dbo].[Payment]( [PaymentID] [int] IDENTITY(1,1) NOT NULL, [OrderID] [int] NOT NULL, [OrderPaymentType] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [PaymentType] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CreditCardNumber] [varbinary](max) NULL, [Last4DigitsOfCreditCardNumber] [nvarchar](4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [ExpirationDate] [varbinary](max) NULL, [CVV2] [varbinary](max) NULL, [Amount] [numeric](18, 2) NOT NULL
3. CREATE TABLE [dbo].[Customer]( [CustomerID] [int] IDENTITY(1,1) NOT NULL, [CustomerCode] AS ([dbo].[udf_FormatCode]('RS',[CustomerID])), [Email] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [FirstName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [MiddleName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [LastName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [DateCreated] [datetime] NOT NULL, [DateModified] [datetime] NOT NULL, [MembershipTypeID] [int] NULL
Please atleast basic structure of stored proc code. It will greatful to me.
I have a table called as Events and below are its columns
ID int EventFromDate datetime EventToDate datetime EventDesc nvarchar IsHoliday bit
This is a master table where the admin would enter the Events/Holidays for the entire year.
The data would be as below:
IDEventFromdateEventTodateEventDesc isHoliday 126-01-201526-01-2015RepublicdayYes 230-01-201531-01-2015TeamOutingNo 301-05-201501-05-2015Labour day Yes
Now, suppose a employee applies leave on 26/01/2015 to 26/01/2015 then it should not insert into table and return a value "Not updated"
How to handle the scenario if a employee applies leave between the range 23/01/2015 to 27/01/2015, since 26/01/2015 is a holiday in between. how the data can still be inserted excluding 26/01/2015
Can we exclude a non-working day or a sunday.
Leavedetails table to insert leaves applied by employee is as follows
LeaveDetailID int LeaveTypeId int FromDate datetime EndDate datetime Remarks nvarchar
I have a table with EmployeeID, StartDate, and EndDate with a PK of EmployeeID, StartDate. How can I check to see that there's no overlap for StartDate and EndDate for a given employee? That is, on any given day there must only be 1 row for an employee where Getdate() is Between StartDate and EndDate. For an active employee their EndDate is set to 06/06/2079.
I've tried it using Row_Number() with Over() but am returning too many rows indicating overlap when none exists.
I've run out of ideas on what to do with a DTS process that has suddenly started giving an error when one company is processed on it.
Here's the deal:
DTS package launches a complex set of stored procedures (built entirely without error handling) as a step in importing data from various customers. I have isolated the error to one segment where I have to cursor through records that have been identified as having changes. Unfortunately, this cursor is updating about 15 system tables and uses modular stored procedures, about 12 of them, to do the job.
Error: The classic Subquery returned more than one value.
Oddity: If I run the code in Query Analyzer I never get an error, the code finishes without complaints. If I run the exact same code via the DTS package I always get the error. Note that the cursor appears to process every row assigned to it and then the sproc throws the error.
What I've Tried: 1) The obvious, reviewing the code for any unprotected subqueries. Haven't found it. 2) Checking for @@Error = 1 at key points in the code to try to isolate where this is happening. Can't catch it.
Note that this same process is used for several other company's data import process and they do not error even when running the DTS package. Therefore I'm assuming it is a data issue with the one company that errors that is causing the problem.
Any suggestions on what to try next would be greatly appreciated!
Just a brief question. I have a script which does a number of insert statements. What I would like to do is determine if the insert statements were all successful. Aside from checking @@ERROR after every insert, is there a way to check if all the insert statements completed successfully?
I have built a procedure to send mail using OLE Automation and want to be able to trap error information when it doesn't work. So in an attempt to do that I have the following stored procedure that will return informaiton if the return value is <> 0. Here is how it is being used:
IF @return <> 0 BEGIN
EXECUTE sp_displayoaerrorinfo @handle, @return
END ELSE PRINT 'Success'
This works fine, but I would like to write the error message to a table and so I thought I could just alter to to be:
Where @failure is a variable I declared earlier. Then I could insert the value of this variable along with some other infomration into a table that would track the errors. However, when I do this I receive the following:
Error: Procedure or Function 'sp_DisplayOAErrorInfo' expects parameter '@HResult', which was not supplied. Number:201 Severity:16 State:4
So it isn't seeing that I am passing two variables into the stored procedure. I know I must be missing something simple but I've tried a bunch of different itterations and can't seem to get it right. Any help would be great. Thanks.
I have a stored procedure that inserts records into the database. It has error checking that checks for transaction failure, and if it happens it rollback the transaction.
IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN END
My question is how can I test if the error checking works?
INSERT INTO databasesize (dbid, updatedate, dbsize) VALUES (5, getdate(), 25) IF @@ERROR <> 0 ROLLBACK TRANSACTION ELSE
COMMIT TRANSACTION
FETCH NEXT FROM dbnames_cursor INTO @dbname, @dbid
END
CLOSE dbnames_cursor DEALLOCATE dbnames_cursor
dbid column in the databasesize table is a primary key, so I when I try to insert records with the same dbid, I can an error message that duplicate row can't be inserted. That is fine, however, when I query databasesize table, there are 4 records with the dbid 5. With the error checking I have I thought I shouldn't get any records in the table, since there is an error transaction should be rolled back. Two questions: Can you tell me what I am doing wrong? Also, I need to add error checking after execute sp_executesql statement. Any suggestions?
INSERT INTO databasesize (dbid, updatedate, dbsize) VALUES (5, getdate(), 25) IF @@ERROR <> 0 ROLLBACK TRANSACTION ELSE
COMMIT TRANSACTION
FETCH NEXT FROM dbnames_cursor INTO @dbname, @dbid
END
CLOSE dbnames_cursor DEALLOCATE dbnames_cursor
dbid column in the databasesize table is a primary key, so I when I try to insert records with the same dbid, I can an error message that duplicate row can't be inserted. That is fine, however, when I query databasesize table, there are 4 records with the dbid 5. With the error checking I have I thought I shouldn't get any records in the table, since there is an error transaction should be rolled back. Two questions: Can you tell me what I am doing wrong? Also, I need to add error checking after execute sp_executesql statement. Any suggestions?
Hi all, We have been checking the database by dbcc checkdb,through a automated task on our production server (nightly task run everday)d we always getting the message given below.
Msg 625, Level 20, state 1 Could not retrieve row from logical page 957298 via RID because the entry in the offset table (=0) for that RID (=17) is less than or equal to 0.
If anyone knows about this error message, can you kindly post the message.
This maybe belongs in the Data-Access Forum, but I'm not sure.
Is it generally a better idea to enforce things like unique constraints in the Database or the Webform? Say for example I want to make sure no duplicate Social Security Numbers are entered. Is it better to have an "If Exists" clause in my query, with a function to deal with it in the application or is it better to just fire the data to SQL Server and let the unique constraint on the dbase column deal with it? I then still have to have some code in my application to deal with the potential exisatance of that number, so is it a case of tomatoe, tomahtoe? If I understand things correctly, SQL server will return an error code if the piece of data does exist, and I will be able to parse the error code and display a message to the user.
Are there performance/coding issues involved? Best practices?
Is it normal practice to check for @@ERROR after a SELECT statement that retrieves data from a table OR we should only check for @@ERROR after a DELETE/INSERT/UPDATE type of statement? The SQL statement is inside a transaction.
I am stumped on the error reporting with sql server. I was told ineed to return @SQLCode(code showing if successful or not) and@ErrMsg(and the message returned). I am clueless on this.I wrote this procedure: Code: ( text )
I have a table with amount columns and I want the amount column to either insert the value from the database or a zero based on a condition.
For the table rows I use the following to find the amount:
=iif( Fields!TYPE.value="Material" or Fields!TYPE.value="Other", FIELDS.Amount.Value,0)
which works fine. However, when I try to Sum in the group foot I get #Error when I use
=sum(iif( Fields!TYPE.value="Material" or Fields!TYPE.value="Other", FIELDS.Amount.Value,0) )
for the groupings that have a type other than Material and Other. For some reason, it doesn't total the amounts of Material and Other with the Zeroes that were placed in the table rows based on the Condition.
For example, the subtotal errors out when trying to total Material with Labor but if it was just Material and Other, it works.
Originally got this error as the reason some of my .rptproj files could not be converted from SRS 2000 to 2005. Now I€™m getting this error when checking out a report from Visual Source Safe 6.0€¦any clue as to what it means?
Project item '4294967294' does not represent a file.
This is for a solution created and stored in VSS using VS2003 and SRS 2000. Now trying to open with VS 2005.
Hi,I have a problem with updating a datetime column,When I try to change the Column from VB I get "Incorrect syntax near'942'" returned from [Microsoft][ODBC SQL Server Driver][SQL Server]'942' is the unique key column valueHowever if I update any other column the syntax is fineThe same blanket update query makes the changes no matter what isupdatedThe problem only happens when I set a unique key on the date field inquestionKey is a composite of an ID, and 2 date fieldsIf I allow duplicates in the index it all works perfectlyI am trying to trap 'Duplicate value in index' (which is working onother non-date columns in other tables)This is driving me nutsAny help would be appreciated
hi, my Date field in the database formated as 2/15/2006 11:40:46 AM . i try to manually give a date (no) but it give me error. the error come from myReader!. help me to correct, thanks
no = "2152006" Dim myConn As SqlConnection Dim myCmd As SqlCommand = New SqlCommand Dim myReader As SqlDataReader Dim strSQL As String
myConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnStr")) strSQL = "SELECT Author FROM Booktbl WHERE cast(Date as datetime) ='" & no & "'" myCmd.CommandText = strSQL myConn.Open() myCmd.Connection = myConn myReader = myCmd.ExecuteReader myReader.Read()
HiI am using SQL 2005, VB 2005I am trying to insert a record using parameters using the following code as per MotLey suggestion and it works finestring insertSQL; insertSQL = "INSERT INTO Issue(ProjectID, TypeofEntryID, PriorityID ,Title, Area) VALUES (@ProjectID, @TypeofEntryID, @PriorityID ,@Title, @Area)"; cmdInsert SqlCommand; cmdInsert=new SqlCommand(insertSQL,conn); cmdInsert.Parameters.Add("@ProjectID",SqlDbType.Varchar).Value=ProjectID.Text; My query is how to detail with dates my previous code wasinsertSQL += "convert(datetime,'" + DateTime.Now.ToString("dd/MM/yy") + "',3), '";I tried the code below but the record doesn't save?string date = DateTime.Now.ToString("dd/MM/yy"); insertSQL = "INSERT INTO WorkFlow(IssueID, TaskID, TaskDone, Date ,StaffID) VALUES (@IDIssue, @IDTask, @TaskDone, convert(DateTime,@Date,3),@IDStaff)"; cmdInsert.Parameters.Add("IDIssue", SqlDbType.Int).Value = IDIssue.ToString();cmdInsert.Parameters.Add("IDTask",SqlDbType.Int).Value = IDTask.Text;cmdInsert.Parameters.Add("TaskDone",SqlDbType.VarChar).Value = TaskDoneTxtbox.Text;cmdInsert.Parameters.Add("Date",SqlDbType.DateTime).Value = date;cmdInsert.Parameters.Add("IDStaff",SqlDbType.Int).Value = IDStaff.Text;Could someone point to me in the right direction?Thanks in advance
Hi Playing around on server at new giggerooo. SELECT CAST('2007-01-28'ASDATETIME)throws:Msg 242, Level 16, State 3, Line 1The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.This:SELECT CAST('20070128'ASDATETIME)Works fine. ASFAIK (or recall) former is SQL Standard, latter is ISO. Should I just start using the ever-so-slightly-less-readable YYYYMMDD format or is there a specific setting I should be looking at and perhaps change? SS 2KLanguage: English (United States)Collation: Latin1_General_CI_AI Ta:)
while using following function I am getting this Error "Msg 195, Level 15, State 10, Line 1 'DATE' is not a recognized built-in function name."
select callid, DATE(segstart) AS calldate from October_CLI.dbo.raw Where callid >0 Segstart Column = Data with call date & time Callid Column = Unique Call Id October_CLI.dbo.raw = Table Calldate = Where i want the only date to be capture from segstart column
i am passing date value from a textbox in c# and asp.net. i am calling an sql procedure . The result is binding to a datagrid. my sql procedure is like this
) as DECLARE @SQL varchar(5000) SET @SQL = 'select Customers.CustomerFirstName as Name,ComplaintLog.LogDate,ComplaintLog.LogID, ComplaintLog.ComplaintStatus,ComplaintLog.DueDate,ComplaintCategories.CategoryName from ComplaintLog Join ComplaintCategories on ComplaintLog.CategoryID=ComplaintCategories.CategoryID join Customers on ComplaintLog.CustomerID=Customers.CustomerID where ComplaintLog.IsActive=1'
IF Datalength(@FirstName)>0 SET @SQL = @SQL + ' AND Customers.CustomerFirstName LIKE ''' + @FirstName + '%'''
IF Datalength(@DueDate)>0 SET @SQL = @SQL + ' AND Convert(DateTime(10),ComplaintLog.DueDate,101) = '+@DueDate + ' '
EXEC (@SQL) GO
my error is Syntax error converting datetime from character string.
if i pass nothing in test boxit will show another error
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
I am trying to import a table from Pervasive into SQL 2000 however I am getting an error due to a date column with some dates of 0000-00-00. How can I import the data without errors?
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Here is the About information from . Microsoft SQL Server Management Studio 9.00.1399.00 Microsoft Analysis Services Client Tools 2005.090.1399.00 Microsoft Data Access Components (MDAC) 2000.085.1117.00 (xpsp_sp2_rtm.040803-2158) Microsoft MSXML 2.6 3.0 5.0 6.0 Microsoft Internet Explorer 7.0.5730.13 Microsoft .NET Framework 2.0.50727.1433 Operating System 5.1.2600
I know this is not the best way to use datetime or conversions, but I did not write it, I am just supporting it.
The strange thing is, the above code has worked every week since January 2006?
The even stranger thing is, it runs on perfectly well on Server 2000 and on the version below that has not had any recent service packs installed.
Microsoft SQL Server Management Studio 9.00.3042.00 Microsoft Analysis Services Client Tools 2005.090.3042.00 Microsoft Data Access Components (MDAC) 2000.086.1830.00 (srv03_sp1_rtm.050324-1447) Microsoft MSXML 2.6 3.0 6.0 Microsoft Internet Explorer 6.0.3790.1830 Microsoft .NET Framework 2.0.50727.42 Operating System 5.2.3790
Is this a bug, or have I lost the plot?
Thanks in advance for any feedback.
P.S: The style code 101, if changed to 103 allows the code to work. But, when apllied to the pre-RTM server, is returns the same error message.
As you can see Col1 & Col2 ONLY do not make up the PK. I need to include Col3 as well. My concern is I am not sure if I have a row like.. 1...........2.......A......X reapeated lower down the order. So how do I figure the PK out?
I'm using ODBC (System DSN) to connect to SQL Server 7.0 Database. Whenever I try to connect to SQL Server Database from my client application, I'm getting the following error message -
---------------------------------------------------------- Microsoft SQL Server has reported the following error:
[Microsoft] [ODBC SQL Server Driver] Invalid Date format ----------------------------------------------------------
After this message, I'm getting another error message -