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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
weddellCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.