Click here to Skip to main content
15,926,596 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Query Pin
_AK_30-Aug-06 0:07
_AK_30-Aug-06 0:07 
QuestionHow to maintain isolation level in MSSQL SERVER 2000? Pin
param thaker29-Aug-06 19:12
param thaker29-Aug-06 19:12 
AnswerRe: How to maintain isolation level in MSSQL SERVER 2000? Pin
Mike Dimmick30-Aug-06 0:18
Mike Dimmick30-Aug-06 0:18 
GeneralRe: How to maintain isolation level in MSSQL SERVER 2000? Pin
param thaker30-Aug-06 3:07
param thaker30-Aug-06 3:07 
QuestionBULK INSERT with CONVERT or CAST? Pin
Yong Yau29-Aug-06 16:36
Yong Yau29-Aug-06 16:36 
AnswerRe: BULK INSERT with CONVERT or CAST? Pin
Sage30-Aug-06 14:33
Sage30-Aug-06 14:33 
GeneralRe: BULK INSERT with CONVERT or CAST? Pin
Yong Yau31-Aug-06 16:01
Yong Yau31-Aug-06 16:01 
GeneralRe: BULK INSERT with CONVERT or CAST? Pin
Sage1-Sep-06 0:17
Sage1-Sep-06 0:17 
This was thrown together, but should work if you replace the tablenames, columnnames and filenames with values that apply to your application

BULK INSERT DBName.dbo.StagingTable -- StagingTable can be a copy of your destination table
From 'C:\YourFile.txt' -- actual path to your file
With (
FieldTerminator = ',',
RowTerminator = '\n' -- for new line
)

Alter Table StagingTable
ADD SafeToTransfer BIT NOT NULL Default(1)


-- Run some integrity checks prior to attempting to tranfer

if ( select Count(*) From DBName.dbo.StagingTable Where IsNumeric( ColumnA )=0 ) >0
BEGIN
Update DBName.dbo.StagingTable
Set SafeToTransfer = 0
Where IsNumeric( ColumnA )=0
END


if (select Count(*) From DBName.dbo.StagingTable Where isDate( ColumnB )=0 ) >0
BEGIN
Update DBName.dbo.StagingTable
Set SafeToTransfer = 0
Where isDate( ColumnB )=0
END


if ( select Count(*) From DBName.dbo.StagingTable Where isNumeric( ColumnD )=0 ) >0
BEGIN
Update DBName.dbo.StagingTable
Set SafeToTransfer = 0
Where isNumeric( ColumnD )=0
END



Insert Into DBName.dbo.DestinationTable
(
ColumnA, -- an INT Column
ColumnB, -- a datetime column
ColumnC, -- a varchar(100) column
ColumnD, -- a numeric(9,5) column
ColumnE -- another varchar(100) column
)
SELECT
CAST( ColumnA as int), -- an INT Column
CAST( ColumnB as datetime), -- a datetime column
LEFT( ColumnC, 100), -- a varchar(100) column
CONVERT( numeric(9,5), ColumnD), -- a numeric(9,5) column
LEFT( ColumnE, 100) -- another varchar(100) column
From DBName.dbo.StagingTable
Where SafeToTransfer = 1


Alter Table StagingTable
DROP COLUMN SafeToTransfer
Questionsql Table Lookup best methods? Pin
ronhawker29-Aug-06 12:31
ronhawker29-Aug-06 12:31 
AnswerRe: sql Table Lookup best methods? Pin
kumarprabhakar7430-Aug-06 2:40
kumarprabhakar7430-Aug-06 2:40 
QuestionError In Visul C++ .net About Oledb Pin
javad_200529-Aug-06 10:20
javad_200529-Aug-06 10:20 
AnswerRe: Error In Visul C++ .net About Oledb Pin
Mike Dimmick29-Aug-06 11:52
Mike Dimmick29-Aug-06 11:52 
QuestionSql database access Pin
sgeezee29-Aug-06 9:11
sgeezee29-Aug-06 9:11 
AnswerRe: Sql database access Pin
Stephen McGuire29-Aug-06 12:01
Stephen McGuire29-Aug-06 12:01 
GeneralRe: Sql database access Pin
sgeezee30-Aug-06 3:13
sgeezee30-Aug-06 3:13 
Questionsmalldatetime in datagrid Pin
TheJudeDude29-Aug-06 8:07
TheJudeDude29-Aug-06 8:07 
AnswerRe: smalldatetime in datagrid Pin
Stephen McGuire29-Aug-06 12:09
Stephen McGuire29-Aug-06 12:09 
GeneralRe: smalldatetime in datagrid Pin
TheJudeDude29-Aug-06 15:25
TheJudeDude29-Aug-06 15:25 
GeneralRe: smalldatetime in datagrid Pin
Stephen McGuire30-Aug-06 8:48
Stephen McGuire30-Aug-06 8:48 
GeneralRe: smalldatetime in datagrid Pin
TheJudeDude30-Aug-06 11:41
TheJudeDude30-Aug-06 11:41 
QuestionNeed Help with AUTO_INCREMENT Pin
Jethro6329-Aug-06 4:20
Jethro6329-Aug-06 4:20 
AnswerRe: Need Help with AUTO_INCREMENT Pin
Eric Dahlvang29-Aug-06 5:25
Eric Dahlvang29-Aug-06 5:25 
GeneralRe: Need Help with AUTO_INCREMENT Pin
Jethro6329-Aug-06 5:38
Jethro6329-Aug-06 5:38 
GeneralRe: Need Help with AUTO_INCREMENT Pin
Eric Dahlvang29-Aug-06 5:57
Eric Dahlvang29-Aug-06 5:57 
GeneralRe: Need Help with AUTO_INCREMENT Pin
Jethro6329-Aug-06 6:06
Jethro6329-Aug-06 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.