473,508 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem converting access queries to sql

1 New Member
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.
Feb 20 '08 #1
1 1351
jagged
23 New Member
Quick and dirty, something like this:

Expand|Select|Wrap|Line Numbers
  1. DECLARE @sql nvarchar(1000)
  2. DECLARE @i int
  3. DECLARE @strI varchar(2)
  4.  
  5. DECLARE @rst nvarchar(100)
  6.  
  7.  
  8. DECLARE curRst CURSOR FOR
  9. SELECT * FROM whatever_rst_is INTO @rst
  10.  
  11. -- Not sure anymore what rst (with no properties/methods) equals in access
  12.  
  13. OPEN curRst;
  14.  
  15. FETCH NEXT FROM curRst;
  16. WHILE @@FETCH_STATUS = 0
  17. BEGIN
  18.     SET @i = 1    
  19.     WHILE (@i <= 20)
  20.         BEGIN
  21.             SET @i = @i + 1
  22.             SET @strI = CONVERT(varchar, @i)
  23.  
  24.             SET @sql = '
  25.             INSERT INTO table2_new (id, material, percent, note)
  26.             SELECT id, matl' + @strI + 'ID, per' + @strI + ', note' + @strI + '
  27.             FROM table1
  28.             WHERE id = ' + @rst + ' 
  29.  
  30.             EXEC (@sql)
  31.  
  32.         END
  33.  
  34.     FETCH NEXT FROM curRst INTO @rst
  35. END
  36. CLOSE curRst
  37. DEALLOCATE curRst    
  38.  
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?
Feb 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2283
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...
4
2000
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...
7
17373
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...
14
2418
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...
0
3910
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....
32
12472
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 ...
12
2489
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.
4
3300
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....
2
1982
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"...
1
1515
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 ( , , ,...
0
7123
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...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7495
tracyyun
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...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
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...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.