|
I have done this hundreds of times; however I am getting stumped on why the date will not convert. I have tried using both CAST and CONVERT.
I am using DTS to export a table to a CSV flat file. There are four fields that need to be converted, all have some null values. I am not including the nulls in the export, NO NULL.
The field Data Types are varchar (255).
The date in the fields are store in the following format 2003-12-11 (no time stamp) and I need to export them as 12-11-2003 (no time stamp). - vs / makes no difference.
I have tried the following in a query.
CONVERT (varchar,DATE1,101) NO NULL,
export does not convert, results in 2003-12-11.
CAST (DATE1 AS DATETIME) AS DATE NO NULL,
export does not convert, results in 2003-12-11.
Thanks for your help.
-- modified at 15:06 Monday 6th August, 2007
Jack Fleet
|
|
|
|
|
Use the VBScript features of DTS to perform a transform. You then get all the power of VBScript to format things however you want.
|
|
|
|
|
Thanks,
Ouch thou, I am not a vbscript writer.
Any help on it would be appreciated.
Jack Fleet
|
|
|
|
|
I have a table tblSummarySells which have columns column1, column2, column3,
column4, column5, column6,column7.
I want a stored procedure which will take parameters @c1,@c2,@c3,@c4,@c5,@c6,@c7 for each column respectively....
it will check for the @c1,@c2,@c3,@c4 already present in the tblSummarySells or not
1. If present then it will update the table values of column5, column 6, column7...
2. If not present it will insert the values into the table....
Need help urgent
|
|
|
|
|
For SQL-Server, your code should be something like:
create procedure MyProcedure
@c1 int,
@c2 int,
@c3 int,
@c4 int,
@c5 int,
@c6 int,
@c7 int
as begin
set nocount off
update MyTable set c5 = @c5, c6 = @c6, c7 = @c7
where c1 = @c1
and c2 = @c2
and c3 = @c3
and c4 = @c4
if (@@ROWCOUNT = 0) begin
insert into MyTable (c1, c2, c3, c4, c5, c6, c7)
values (@c1, @c2, @c3, @c4, @c5, @c6, @c7)
end
return (0)
end I have assumed that all of your variables are integers, and that none of your primary key columns can be null.
Regards
Andy
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".
|
|
|
|
|
Thanks
But I have data already in table so is @@rowcount=0 going to work
|
|
|
|
|
The @@ROWCOUNT variable holds the number of records hit by the previous update statement.
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".
|
|
|
|
|
In Sql Server from version 2000 onwards there is a feature called an INSTEAD OF trigger that you can use. To use it, you create a copy of your table as a view and use this as the target of your inserts. Behind this view, create a trigger with the signature INSTEAD OF INSERT where you would normally put the FOR INSERT.
The trigger would look something like this:
CREATE TRIGGER InsertIntoSummarySells
INSTEAD OF INSERT
AS
BEGIN
DECLARE @C1 INT -- or whatever type it is
DECLARE @C2 INT -- ...
... -- And so on, with the parameters
SET NOCOUNT ON
UPDATE tblSummarySells
SET C5 = @C5,
C6 = @C6,
C7 = @C7
WHERE
C1 = @C1 AND C2 = @C2 AND C3 = @C3 AND C4 = @C4
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO tblSummarySells ....
END
END Now, the advantage of this approach is that anytime you do an insert onto the view, this code will run so it should always behave consistently - rather than having to remember to call the stored procedure to perform the update.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I am getting following exception in the code below
Exception occurs when closing connection,
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
The SqlCommandTimeout is already set 0 as you can see in the code below,
When i search records for first time it works fine, but the exceptions start coming second time or third time onwards,..
Protected Overrides Sub DataPortal_Fetch(ByVal criteria As Object)
' Load object data from database.
Dim crit As criteria = DirectCast(criteria, criteria)
Dim con As New SqlConnection(DB())
// db string is something like
//"data source=hurst\SQL2000_SP4;initial catalog=MYDB_OOP_11;Connection Timeout=60;user=asd_user;password=asd_user;"
Dim cmd As New SqlCommand
con.Open()
Try
With cmd
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandTimeout = 0
' Set up and call appropriate stored procedure.
If crit.IsSimpleList Then
.CommandText = DBObject & "_info_simple_get"
With .Parameters
// some code for adding params for SP
End With
Else
.CommandText = DBObject & "_info_get"
With .Parameters
// adding param for Stored Procedure here
End With
End If
Dim dr As New SafeDataReader(.ExecuteReader)
Try
Me.Fetch(dr, crit.IsSimpleList)
// The fectch function loops for each read of datareader and creates a new object, passing it dr object, each object then reads its column from dr
Finally
dr.Close()
End Try
End With
Finally
con.Close() // I get exception here..on closing..
End Try
End Sub
Is it something because of improper use of DataReader ? or what is it, I really couldnt figure out, I have Tried using GC.collect() etc , but no use,
please help
Ahmed
Ahmed
|
|
|
|
|
U can Set ur own time for the connection and try.....
If U Get Errors U Will Learn
If U Don't Get Errors U Have Learnt
|
|
|
|
|
I would suspect that your problem is more to do with the connection timeout you are using in your connection string.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi
I use the following code to add a row to my database using ADO.NET in VB.NET:
Dim strConnstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DB.mdb"
Dim Sql As String = String.Format("INSERT INTO Employee(FName,LName,Salary) VALUES('{0}','{1}',{2})", txtFirstName.Text, txtLastName.Text, txtSalary2.Text)
Dim Conn As New OleDbConnection(strConnstring)
Dim Comm As New OleDbCommand(Sql, Conn)
Dim DA As New OleDbDataAdapter(Comm)
Dim DS As New DataSet
Conn.Open()
Comm.ExecuteNonQuery()
Conn.Close()
Everything looks fine, the datagrid which shows Employee table, shows that the item is added.
But DataAdapter does not update the dataset! I noticed that when I add a row by this method, the State of the row is not set to Added, like when I use Rows.Add (which works just fine!)
I need to do this using this SQL command, but how to update the database also?
(I again notice that myDataSet.GetChanged is null!)
|
|
|
|
|
Hi,
I have configured MAPI profile using POP3 and the same profile has been configured in SQL server 2000 in SQL server Agent(Management) and in SQL Mail(Support Services).Mail is sent successfully when we compose it manually through Microsoft office outlook.The problem is that when i execute XP_sendmail stored procedure is executing fine and the output is Mail Sent.But the mail is remaining in outlook itself.When i open the outlook Send/Receive is happening and the mail is sent successfully.Unless i open outlook Iam unable to send the mail.Please suggest me what would be the possible solution for this.Any help from you side is appreciated.Thanks in Advance.
regards,
Shaik.
|
|
|
|
|
My only advice is not to use SQL Server 2000 built-in mail capabilities - consider using blat.exe[^].
This[^] may be helpful.
|
|
|
|
|
Hi,
I need to bring back records in a certain date range.
I need it to be from May 2007 to August 2007. I can pass through (2007 and 5) and (2007 and 8) but not sure how my WHERE will look like.
Please can some one help??
Regards
ma se
|
|
|
|
|
searching on datetime column for dates between May-2007 and Aug-2007
DECLARE @Mth1 varchar(5)
DECLARE @Yr1 varchar(5)
DECLARE @Mth2 varchar(5)
DECLARE @Yr2 varchar(5)
SET @Mth1 = '5'
SET @Yr1 = '2007'
SET @Mth2 = '8'
SET @Yr2 = '2007'
DtCol >= Convert(datetime, '01/' + @Mth1 + '/' + @yr1, 103)
AND DtCol < DateAdd(m, 1, Convert(datetime, '01/' + @Mth2 + '/' + @yr2, 103))
here the condition is starting from 1st of May-2007 to 31st of Aug-2007
i.e. deriving both dates initial date would be 1st of the month and ending date is less than 1st of required month + 1
Regards
KP
|
|
|
|
|
Dear All ,
I am trying to parse a huge text files(size: 50kb to 1MB).
Currently I have developed a mechanism using regular expressions which
can group the values in each and every line, finally the values are
formatted into a XML string which is passed into a stored procedure
where the XML is loaded and again by using OPENXML statement I read
all the values and records are inserted into the tables. My problem
here is with the execution time of the Stored Procedure which is
taking nearly 45 secs to execute the XML string.
Row Count ranges from 100 to 2000.
Column count is 40.
Can anyone please suggest me an alternate method or the necessary step
which I can do with the front end and back end.
Thanks and Regards,
Valan.
|
|
|
|
|
|
I have a limitation in using the BULK INSERT or BCP,
It is a text file of unicode characters with txt extension.
Actual file information will start from
fifth line and it will end before the last second line.
Business logic has to be implemented like validating the
format of file and validating the values of the field,
due to these type of requirements I prefered to apply
regular expressions from front end and formatted values
are converted into XML strings.
I 'am using SQL Server 2000, and .NET 2.0
Can you please suggest me with better method to follow.
Thanks
Valan.
|
|
|
|
|
How about, instead of converting data to XML, changing the TXT file format (and performing all the necessary validation), so bcp /BULK INSERT can process it?
|
|
|
|
|
Mr. Chopeen,
Are you sure by using the BULK INSERT I will be able to reduce the
execution time, then I will try in all the possible ways to use
the BULK INSERT to complete my File Parsing.
Is that only the better and best way for inserting records into the
DataBase?
Please suggest me.
Thanks and Regards
Valan
|
|
|
|
|
A completely different idea just came to my mind - you are using some kind of .NET application to generate the XML file, aren't you? Can't you change it and generate INSERT statements? Then you will have to simply execute those INSERT-s.
|
|
|
|
|
Ok Fine thanks I will try to do with your suggestion.
But any Idea why it has to take a longer time for XML
execution.
Thanks and Regards
Valan
|
|
|
|
|
I don't have much experience with XML so I'm not sure I will be able to help, but if you post your stored procedure I'll take a look.
|
|
|
|
|
This is my mail ID tonic_valan@hotmail.com,
if you are willing I can mail my SP.
|
|
|
|
|