Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problems with Insert

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-09-30 : 05:18:31
I have the following code, which works, but I need to amend it and don't know how !

The line below I have amended to show what I want, but the syntax is all wrong

For this line below I want to insert FA_ITem concatenated with Newdate, so creating a unique value. eg FA_Item"'*'"Newdate. It will appear as PrinterA*01/10/05 in my table. I also want to do it in a stored procedure, but if I can get it working as it is it will be something. Thanks for any help.

*
Dim strSQL As String = "Insert tblRB_FacilitiesDates(FD_FacilitiesRef, FD_DateRequired, FA_Item) " _
& " select FA_Item &"'*'"& Newdate, '" & Newdate & "' ,'" & FA_Item & "'& from tblRB_Facilities"
*




Dim strConnection As String
Dim myconnection As New SqlConnection
strConnection = ConfigurationSettings.AppSettings("ConnectionString")
myconnection = New SqlConnection(strConnection)

Dim Newdate As Date = Today.ToShortDateString
Dim x As Integer
For x = 1 To 10

Newdate = DateAdd("d", x, Newdate)

Dim strSQL As String = "Insert tblRB_FacilitiesDates(FD_FacilitiesRef, FD_DateRequired) " _
& " select FA_Item, '" & Newdate & "' from tblRB_Facilities"

Dim Cmd As New SqlCommand(strSQL, myconnection)
myconnection.Open()
Cmd.ExecuteNonQuery()
myconnection.Close()
Next

Kaleem021
Starting Member

26 Posts

Posted - 2005-09-30 : 06:22:21
Try This

Dim strSQL As String = "Insert tblRB_FacilitiesDates(FD_FacilitiesRef, FD_DateRequired) " _
& " select FA_Item + '*' + '" & Newdate & "', '" & Newdate & "' from tblRB_Facilities

*****************************************************************************
Myth Breaker
Kaleem021@hotmail.com

Doing Nothing Is Very Hard To Do, You Never Know When You Are Finished.
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-09-30 : 06:57:43
Thanks - that works fine.
Go to Top of Page
   

- Advertisement -