Sql with Visual C++ or Visual basic kindly help
Take user input n as an integer
If user inputs n= 3 The I should create a table with 3 fields say d1 d2 d3
If user inputs n=4 The I should create a table with 4 fields say d1 d2 d3 d4
If user inputs n=5 The I should create a table with 5 fields say d1 d2 d3 d4 d5
Re: Sql with Visual C++ or Visual basic kindly help
The SQL syntax for CREATE TABLE is
CREATE TABLE "table_name" ("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )
You should google for the way to execute this statement using the prog language and the data access that You are using or want to use
JG
Re: Sql with Visual C++ or Visual basic kindly help
How to change the number of column's dynamically on each execution of procedure based on the value of n.
Re: Sql with Visual C++ or Visual basic kindly help
Something like this...
Code:
Dim MyStr As String
MyStr = "CREATE TABLE [dbo].[tablename] ("
Select Case n
Case 1
MyStr = MyStr & "[fieldname1] [datatype] (lenght)"
Case 2
MyStr = MyStr & ",[fieldname2] [datatype] (lenght)"
Case 3
MyStr = MyStr & ",[fieldname3] [datatype] (lenght)"
'and so on
End Select
MyStr = MyStr & ")"
MsgBox MyStr
JG
Re: Sql with Visual C++ or Visual basic kindly help
The is OK only if we know what values are permmisble for n say only 1,2,3 or 100
But if the user types n=100 it should create table with field names
d1,d2,d3,....,d100 all varchar
n=101 it should create table with field names
d1,d2,d3,....,d100,d101 all varchar
etc.
Re: Sql with Visual C++ or Visual basic kindly help
Then You could try a Do-Loop or a For-Next iteration
JG