Create the table SQL server = VB 6.0

I have 1 sort code. It is Procedure creat the IDTEMP Table

DECLARE @Col1 int,
     @sql nvarchar(1000)

DECLARE curA CURSOR FOR
SELECT Distinct BangHeSo.TenTruong FROM BangDinhNghia INNER JOIN BangHeSo ON BangDinhNghia.KS_Tuyen_Via_LK_id = BangHeSo.KS_Tuyen_Via_LK_id INNER JOIN Tuyen_LoKhoan ON BangDinhNghia.Tuyen_Lokhoan_id = Tuyen_LoKhoan.tuyen_lokhoan_id INNER JOIN LoKhoan ON Tuyen_LoKhoan.lokhoan_id = LoKhoan.lokhoan_id INNER JOIN Tuyen ON Tuyen_LoKhoan.tuyen_id = Tuyen.tuyen_id INNER JOIN VungKhoangSan ON BangDinhNghia.VungKhoangSan_id = VungKhoangSan.vungkhoangsan_id WHERE (VungKhoangSan.tenvungkhoangsan ='" & cmbKS & "') AND (BangDinhNghia.TenVia ='" & cmdvia & "') AND (BangHeSo.TenPhuongAn ='" & cmbPA & "')

OPEN curA
FETCH NEXT FROM curA INTO @Col1

WHILE @@FETCH_STATUS=0
BEGIN
     if exists (select * from dbo.sysobjects where id = object_id(N'[IDTEMP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
     BEGIN
          SELECT @sql = 'ALTER TABLE IDTEMP ADD [' + convert(varchar,@Col1) + '] varchar'
          exec sp_executesql @sql
     END
     ELSE
     BEGIN          
         
          SELECT @sql = 'CREATE TABLE IDTEMP([' + convert(varchar,@Col1)+ '] varchar)'
          exec sp_executesql @sql
     END    

FETCH NEXT FROM curA INTO @Col1
END

CLOSE curA
DEALLOCATE curA

- I write This code in VB 6.0 then code apper red colors
Help me,Where I must write this code
Thank you.
doanketAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
weddellConnect With a Mentor Commented:
Not directly, no, but you can send SQL statements to SQL Server using the CommandText property of ADO but the first SQL script you posted had cursors(SQL loops) which you wont be able to do in a single SQL statement.

Do you have SQL Server running on your server?
Do you have SQL Server Enterprise Manager running on your computer?

If you have SQL Server on the server but don't have Enterprise Manager, you can create the stored procedure in your question using VB and then call it? Is that what you want?
0
 
weddellCommented:
Not sure what your asking, but you appear to be saying your trying to write this code in VB6? It is Transact SQL and need to be written in Microsoft SQL Server as a new Stored Procedure.
0
 
doanketAuthor Commented:
Yes.
But Command
SELECT Distinct BangHeSo.TenTruong FROM BangDinhNghia INNER JOIN BangHeSo ON BangDinhNghia.KS_Tuyen_Via_LK_id = BangHeSo.KS_Tuyen_Via_LK_id INNER JOIN Tuyen_LoKhoan ON BangDinhNghia.Tuyen_Lokhoan_id = Tuyen_LoKhoan.tuyen_lokhoan_id INNER JOIN LoKhoan ON Tuyen_LoKhoan.lokhoan_id = LoKhoan.lokhoan_id INNER JOIN Tuyen ON Tuyen_LoKhoan.tuyen_id = Tuyen.tuyen_id INNER JOIN VungKhoangSan ON BangDinhNghia.VungKhoangSan_id = VungKhoangSan.vungkhoangsan_id WHERE (VungKhoangSan.tenvungkhoangsan ='" & cmbKS & "') AND (BangDinhNghia.TenVia ='" & cmdvia & "') AND (BangHeSo.TenPhuongAn ='" & cmbPA & "')
in VB 6.0
Can I write Transact SQL in Vb?

Thank you
0
All Courses

From novice to tech pro — start learning today.