I'm on the process of migrating in SQL server. We have an access mdb.
i have this table in access and i want to divide this into two separte table. i dont know how to convert this into t-sql code to divide this table into two.
the format of the old table is:
Table1
id, name, desc mat1id, per1, note1, mat2id, per2, note2 .... 20
1 a adesc mat1 1 txt mat2 2
2 b bdesc mat2 2 mat3 4
--- New table
Ntable1
id, name, desc
1, a adesc
2 b bdesc
Ntable2
id, material, percent, note
1, mat1 1 txt
1, mat2 2
2 mat2 2
2 mat3 4
i dont have problem on creating table1.
i have this code in access for table2. but don't know how to convert this in tsql
Do Until rst.EOF
i = 20
For i = 1 To 20
Docmd.Runsql ("INSERT INTO table2_NEW ( id, material, percent, note) & _
"SELECT id, matl" & i & "ID, per" & i & ", note" & i & " & _
"From table1 " & _
"Where id = '" & rst & "' And Not IsNull(mat" & i & "id)")
Next i
rst.MoveNext
Loop
any idea how to convert this in to tsql.
appreaciate any help.
1 1363
Quick and dirty, something like this: -
DECLARE @sql nvarchar(1000)
-
DECLARE @i int
-
DECLARE @strI varchar(2)
-
-
DECLARE @rst nvarchar(100)
-
-
-
DECLARE curRst CURSOR FOR
-
SELECT * FROM whatever_rst_is INTO @rst
-
-
-- Not sure anymore what rst (with no properties/methods) equals in access
-
-
OPEN curRst;
-
-
FETCH NEXT FROM curRst;
-
WHILE @@FETCH_STATUS = 0
-
BEGIN
-
SET @i = 1
-
WHILE (@i <= 20)
-
BEGIN
-
SET @i = @i + 1
-
SET @strI = CONVERT(varchar, @i)
-
-
SET @sql = '
-
INSERT INTO table2_new (id, material, percent, note)
-
SELECT id, matl' + @strI + 'ID, per' + @strI + ', note' + @strI + '
-
FROM table1
-
WHERE id = ' + @rst + '
-
-
EXEC (@sql)
-
-
END
-
-
FETCH NEXT FROM curRst INTO @rst
-
END
-
CLOSE curRst
-
DEALLOCATE curRst
-
Not sure about this part in your code though: "Where id = '" & rst & "' And Not IsNull(mat" & i & "id)")
Since the variable i always has a value, why would mat" & i & "id ever be null?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Terry Bell |
last post by:
I'm upsizing an Access database. Got the data converted, working on
the front end, converting queries to views, but having trouble
converting queries that use logical expressions like the following:
SELECT OrderId,
Sum((BackOrderQtyAvailable>0)*-1) AS ReadyBackOrderItems
FROM OrderDetails
INNER JOIN Items
ON (OrderDetails.ClientId = Items.ClientId)
AND (OrderDetails.ItemId = Items.ItemId)
WHERE (NOT (SitesCustomerTypeId = 2
|
by: dschl |
last post by:
Hi,
I'm converting an Access 2000 database to Sql Server and must be
missing something obvious.
Using the Import utility in Sql Server, the Access queries seem to get
executed and the resultant data imported as tables. Oops!
Using the Upsize lizard in Access 2003, the queries aren't even in the
selection list of "tables" to upsize. It looks like the Upsize wizard
|
by: Dana Shields |
last post by:
I am attempting to upsize from access to SQL Server. I'm trying to convert
my queries to SQL Server views; however, I'm having a lot of difficulty with
the syntax differences.
For instance, a query with select mid(tblTable.FieldName,1,10)should look
something like select substring(tblTable.FieldName,1,10).
This is really the simplest of examples. I've tried using the SQL Server
Import tool, but it takes the queries and changes them...
|
by: D |
last post by:
Hey guys- not sure where this post fits in, so I cc'd a few other groups as
well- hope you dont mind...
I have someone creating a database for me in Access 2000 (or is it called
XP?). When it's all done, I'd like it to be online via the web. Ultimately
I'd like just an online database accessed via ASP, PHP, CGI, etc- something
(doesn't matter) but where various employees can access the thing from
anywhere and do their work. It's been...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header, example, and DLL:...
| |
by: robert d via AccessMonster.com |
last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections
are of the following structure:
Dim wsName As DAO.Workspace
Dim dbName As DAO.Database
Dim rsName As DAO.Recordset
Set wsName = DBEngine.Workspaces(0)
Set dbName = wsName.OpenDatabase(CurrentProject.FullName)
Set rsName = dbName.OpenRecordset("SQL Statement")
|
by: zMisc |
last post by:
I have a problem selecting records with \ in any values.
For example:
SELECT * FROM ADDRESS WHERE STREET = "A\"
will give an error:
If I replace \ with \\ then it works. Eg.
|
by: Bob Alston |
last post by:
Anyone have experience with converting an access app from Jet database
to Mysql? I am specifically looking for any changes I would have to
make to my access forms, queries, modules, vba code, etc. I understand
there are some data format differences in text field types and date
types that need to be addressed if converting from Jet to Mysql. But
other than things that have to be addressed when converting, what other
changes must I make?...
|
by: MyEmailList |
last post by:
We have an Access data base with severl tables, queries and forms.
We want to put it on the web.
Is there a tool that will convert the Access queries and forms to ASP?
Sorta like "splitting" the database... but instead of an Access Front
End... have an ASP front end?
Thanks for any help.
|
by: rob41 |
last post by:
I'm in the process of converting numerous queries from access 07 to sql server 05 to improve runtime performance. Below is a sample of code and the error I'm getting.
INSERT INTO
( , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , )
SELECT ., ., ., LTrim(.) AS Expr1, LTrim(.) AS , LTrim(.) AS , LTrim(.) AS , LTrim(.) AS , LTrim(.) AS , LTrim(.) AS , LTrim(.) AS , LTrim(.) AS ,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |