|
I have data in input file given below -->
1,abc
2,xyz
------- End of data----
Notice i have an empty rows after second row.
I m doing bulk insert with FIELDTERMINATOR = ',',ROWTERMINATOR = '\n'. It works perfectly fine when bulk inserting after removing the empty records. But when there is empty record at end of file, it is throwing error given below and no records are inserted in db. I cannot ask the user to remove empty line at EOF.
Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
|
|
|
|
|
searching for solution..... wrote: I cannot ask the user to remove empty line at EOF. Then you'll have to write something that removes that line for the user. As the example, I'd expect it to be invalid, as an empty row would consist of field-separators and a row-separator. Like this:
1,abc
2,xyz
, An empty line does not equal an empty row. It equals a row without fields.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
i need get data of checkbox which inside a gridview this grid inside another grid i have used concept called masterdetail row inside it i have placed a control called checkbox now i need to that checked value......... how it is possible please help me with code using asp.net and C#......
Thanks in Advance................
|
|
|
|
|
Please choose the proper forum and post your question once only. I suggest you delete the other two.
Use the best guess
|
|
|
|
|
//for each row of gridview
CheckBox chk;
for (int i = 0; i< GridView1.Rows.Count; i++)
{
chk = (CheckBox)GridView1.Rows[i].Cells[chechboxcolumnIndexInterger].FindControl("checkboxID");
}
|
|
|
|
|
Please help me......
how to upload a iamge file on web server in mvc4 asp.net c#
|
|
|
|
|
SQL Server will return a null date as 01/01/1900 if one castes a null string to a date.
Now the issue is that someone had the idea of populating dates with 01/01/1900 to signify a certain stage with a row(meaning that the date is not known but it is known that that stage has been reached).
I only realised yesterday that this could cause an issue if a query is written where a null string is compared to one of these dates.
Does anyone else have experience of this and any suggestions?
I am currently thinking of changing these 01/01/1900 dates to 01/01/1901 to remedy this potential problem.
Thanks
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Which version of SQL Server? I've just tried with SQL 2008, and casting a varchar containing Null to either datetime , smalldatetime , datetime2(0) or date returns Null in all cases.
http://www.sqlfiddle.com/#!3/d41d8/13023[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello, this is not SQL Server Issue.
This is related to the Connection Type you ar using (ADO.NET, OLE DB, ODBC...).
for example:
If you are using MS Access you will see:
[Null] dates returns/saves [01/01/1900]
[Bit] field returns [-1] or [1]
Just a moment ago a friend asked me about the same problem, he is developing on Visual Studio .NET 2008 SP1 (I really did not checked his code, but he resolved his problem).
Hope this help.
Best regards.
|
|
|
|
|
MS Access might do that but I seriously doubt SQL Server does.
If it is null in the database then a null is returned to .Net. No manner of casting/manipulation at that point in time is going to change that to something that isn't a null.
|
|
|
|
|
I'd suggest adding a bit-column called "HasDate".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
GuyThiebaut wrote: SQL Server will return a null date as 01/01/1900 if one castes a null string to a date.
I seriously doubt that.
As a guess the data is actually an empty string.
|
|
|
|
|
jschell wrote: the data is actually an empty string
Yes, that makes sense:
http://www.sqlfiddle.com/#!3/d41d8/13027[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks.
I will have to check this with regards to the data I have been looking at - however I think you have hit the proverbial nail on the head.
I think I will go with changing the dates to something other than 01/01/1900 as I can see someone in the future doing an isnull comparison on an empty string and getting a match against these dates.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
GuyThiebaut wrote: as I can see someone in the future doing an isnull comparison on an
empty string and getting a match against these dates.
I don't understand that statement so just to be sure I will state that an empty string is not the same as a null value.
|
|
|
|
|
hi to all
i have a while loop like this
declare @Counter int
while(@Counter<1000)
begin
set @Counter = @Counter + 1
select * from mytable where [my where clause]
end
my where cluase change in each repeat.
i want to union all result to a table and return one table as query result
how can i do this ?
performance is very important for me
because while loop can be run for upper 15000
thanks for any help
|
|
|
|
|
mehdi.sabet wrote: my where cluase change in each repeat.
Can you post your where clause? It can probably be replaced with a single query, which will give you much better performance.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
 hello
thanks for reply
my main code is:
ALTER PROCEDURE [dbo].[lfd__GetFullPersonnelDetails]
(
@PersonnelList nvarchar(MAX),
@WorkPeriodID int,
@WorkPeriodYear int
) AS
Declare @startDate SMALLDATETIME
Declare @endDate SMALLDATETIME
Declare @PersonnelBaseID INT
WHILE(LEN(@PersonnelList) > 0)
BEGIN
SET @PersonnelBaseID = SUBSTRING(@PersonnelList, 0, PATINDEX('%,%',@PersonnelList))
IF(@PersonnelBaseID != 0)
SET @PersonnelList = SUBSTRING(@PersonnelList, LEN(CAST (@PersonnelBaseID AS NVARCHAR) + ',') + 1, LEN(@PersonnelList))
ELSE
BEGIN
SET @PersonnelBaseID=CAST(@PersonnelList AS INT)
SET @PersonnelList = SUBSTRING(@PersonnelList, LEN(@PersonnelList + ',') + 1, LEN(@PersonnelList))
END
set @startDate=(select top 1 [date] as startdate
from
lfd_DailyStatistics
where
PersonnelBaseID = @PersonnelBaseID and [Year] = @WorkPeriodYear and WorkingPeriodID = @WorkPeriodID
order by date asc)
set @endDate=(select top 1 [date] as startdate
from
lfd_DailyStatistics
where
PersonnelBaseID = @PersonnelBaseID and [Year] = @WorkPeriodYear and WorkingPeriodID = @WorkPeriodID
order by date desc)
SELECT
dailyAbsences.*,
CAST(CASE WHEN calculationQueue.[StartDate] IS NULL THEN 0 ELSE 1 END AS bit) AS [NeedsRecalculation]
FROM
lfd_dailyAbsence dailyAbsences LEFT JOIN
lfd_CalculationQueue calculationQueue ON dailyAbsences.[PersonnelBaseID] = calculationQueue.[PersonnelBaseID] AND calculationQueue.[StartDate] <= @endDate
WHERE
dailyAbsences.[PersonnelBaseID] = @PersonnelBaseID AND
dailyAbsences.[StartDate] >= @startDate AND
dailyAbsences.[EndDate] <= DATEADD(day, 1, @endDate)
ORDER BY
dailyAbsences.[StartDate]
END
start date and end date change in each repeat
|
|
|
|
|
Little tip - get rid of the order by clause - as it is taking up unnecessary processing time.
You can order the results once you have combined them.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
OK, the first thing you need is a split function:
CREATE FUNCTION dbo.fn_Split
(
@Value varchar(max),
@Delimiter varchar(20) = ','
)
Returns TABLE
As Return
(
WITH cte (Idx, StartIndex, EndIndex) As
(
SELECT
1,
1,
CharIndex(@Delimiter, @Value)
UNION ALL
SELECT
1 + Idx,
CAST(1 + EndIndex As int),
CharIndex(@Delimiter, @Value, 1 + EndIndex)
FROM
cte
WHERE
EndIndex > 0
)
SELECT
Idx,
SubString(@Value, StartIndex, CASE
WHEN EndIndex > 0 THEN EndIndex - StartIndex
ELSE LEN(@Value)
END) As Value
FROM
cte
);
GO
Then you can build a single query:
WITH ctePersonnelList (PersonnelBaseID) As
(
SELECT
CASE
WHEN Value Like '%[^0-9]%' THEN Null
ELSE CAST(Value As int)
END
FROM
dbo.fn_Split(@PersonnelList, ',')
WHERE
Value Not Like '%[^0-9]%'
),
cteDates (PersonnelBaseID, StartDate, EndDate) As
(
SELECT
L.PersonnelBaseID,
Min([date]),
Max([date])
FROM
ctePersonnelList As L
INNER JOIN lfd_DailyStatistics As S
ON L.PersonnelBaseID = S.PersonnelBaseID
WHERE
[Year] = @WorkPeriodYear
And
WorkingPeriodID = @WorkPeriodID
GROUP BY
L.PersonnelBaseID
)
SELECT
A.*,
CAST(CASE WHEN Q.StartDate IS NULL THEN 0 ELSE 1 END AS bit) As NeedsRecalculation
FROM
cteDates As D
INNER JOIN lfd_dailyAbsence As A
ON A.PersonnelBaseID = D.PersonnelBaseID
And A.StartDate >= D.StartDate
And A.EndDate <= DateAdd(day, 1, D.EndDate)
LEFT JOIN lfd_CalculationQueue As Q
ON A.PersonnelBaseID = Q.PersonnelBaseID
And Q.StartDate <= D.EndDate
ORDER BY
A.PersonnelBaseID,
A.StartDate
;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thanks Richard
this is a good solution
|
|
|
|
|
Why not create a temp table and insert the results there? When the while loop is done select * from your temp table.
|
|
|
|
|
ok but what about performance ?
if i done this and this loop execute ,for example , for 15000 repeat
this is a optimal way?
and how can use one temp table and insert all resualt to this temp table?
thank you
|
|
|
|
|
Looping in a database is never efficient. Working with tables is.
Did that answer your question?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
I have just changed the db for a small app from using an MS ACCESS db (terrible thing!) to SSE 2008 R2 DB. Previously, they used to just copy the ACCESS db file each evening to a flash drive, and keep that off site. They have been using the app for a year now, and the SSE backup file is only about 20MB - in other words not that much data to backup. The server instance only has one database, and one additional user, no views or stored procedures or anything like that
1) What exactly do I need to back up? The database, system databases (master, model, msdb etc) log files?
2) How should I do the backup? (Been thinking along the lines of a backup command that can be run from the app (SMO), or possibly having a table in the DB with last backup date/time, and if a user logs on, and the last backup is older that a day, it makes a new backup. Or is there a better way? Can you schedule a job on SSE to do this daily?
3) I'm also not sure what options to use with respect to:
a) Backup Type (Full or Incremental?)
b) Copy-only Backup (No?)
c) Backup to existing medias set (yes) - Overwrite or Append?
4) The code I've tested using SMO
Backup bkp = new Backup();
bkp.Action = BackupActionType.Database;
bkp.Database = databaseName;
bkp.Devices.AddDevice(fileName, DeviceType.File);
bkp.Incremental = chkIncremental.Checked;
bkp.SqlBackup(srv);
Basically I want to end up with a backup (that can possibly be copied to some or other storage device as well for off site storage - flashdisk or portable drive) that in that case of the sever crashing completely, that I could restore to at worst a new instance of SSE?
Am i on the right track here?
Any other suggestions welcome!
modified 1-May-13 2:23am.
|
|
|
|