Question : truncating table and updating from another table converting varchar to int and datetime

I have two tables test and test2

test has two columns updated from csv file
sequence  (nvarchar 50)
date (varchar 50)

then I need to update to test2 as this table is selected by a cube (third party report server) set up as int and datetime
sequence (int)
date (datetime)

my script goes as follows:

truncate table test2
insert into test2  select convert ((int), sequence),
convert ((datetime), date) from test

error message is Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.

where have I gone wrong

Answer : truncating table and updating from another table converting varchar to int and datetime

TazEE,

I will see what I can do to assist.  You posted sample xml file is an invalid xml file as it is missing several closing tags.  I have tried to adjust and work with it.  Below is an adjusted script that should help you along your way.  I have tried to put some comments in to assist.

For you immediate issues of more than one graphic, you need to loop through the Node List that you get.  Right now you are only grabbing the first one found.  Also, I suggest you check to make sure it has a graphic ID as your sample had some AD nodes without a graphic ID.  Let me know if you have questions as you work through the script.

Instead of writing out to a file I just kept all the graphic IDs in a string array in memory (strGraphicList)

-Bear
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
Dim fso, outfile, Graphic, Elem
Dim strFromDir, strToDir, strGraphicList(), i
Set fso = CreateObject("Scripting.FileSystemObject")

' **** Set your Directory Values Here ****
strFromDir = "C:\Original"
strToDir = "C:\New"
i = 0

Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("C:\test\test.XML")

Set ElemList = xmlDoc.getElementsByTagName("Ad")

' ElemList.Length will show you how many AD nodes you found
' msgbox ElemList.Length

' Loop Through your Node List
For Each Elem in ElemList

	' Check to see if this Node has an Attribute Named Graphic
	If not Elem.getAttribute("Graphic") Then
		' Make sure the Array is the right Size
		Redim Preserve strGraphicList(i)
		
		' If so, assign the attributes value to an Array
		strGraphicList(i) = Elem.getAttribute("Graphic")
		
		' Increment the counter
		i = i + 1
	End If
Next


' Loop Through the Array
For i = 0 to Ubound(strGraphicList) - 1
	' Make sure the original File Exists in the Source
	If fso.FileExists(sstrFromDir & "\" & strGraphicList(i)) Then
		' Found the File - Copy to Destination
		fso.CopyFile strFromDir & "\" & strGraphicList(i), strToDir & "\"
	End If
Next
		
' Validate that All Files exit in Destination
For i = 0 to Ubound(strGraphicList) - 1
	' Make sure the original File Exists in the Source
	If NOT fso.FileExists(strToDir & "\" & strGraphicList(i)) Then
		' Found NOT Found
		msgbox "Graphic ID " & strGraphicList(i) & "was not found"
	End If
Next
		
msgbox "Done"
Random Solutions  
 
programming4us programming4us