Jump to content

Dynamic procedure variables


alanl1
Go to solution Solved by boompa,

Recommended Posts

Hi All

 

 

I have a loop in php which loops through all the values from a previous page like so

 
foreach ($_POST['textbox'] as $datanumcolumns=>$datadownboxValue){

 echo "Textbox value" .$datanumcolumns. " has a value of " .$datadownboxValue. " "?><br /><?php

}

I also have a sql procedure which passes in variables of

1:csv file

2:table to be created and

3: column count from my loop as shown below

 
$sql = "exec importspreadsheet " . "'" . $newfilename . "'," ."'" .$table_name."'," ."'" .$datanumcolumns."' ";

from that within my sql procedure I iterate through the column count and create the database table which builds up a table like so

while (@intflag < @column_count-3)
begin
set @midcolumns = 'colname' + cast(@intflag as nvarchar(2)) + ' nvarchar(max) null,';
set @middlecolumns = @middlecolumns + @midcolumns;
set @intflag = @intflag +1;
end
 

this produces column1,column2,column3,column4 etc minus my first 3 standard column i have

 

does anyone know if there is a way to pass the actual column values in so for instance if there were 6 columns it would pass in

 

exec impostspreadsheet SPREADSHEETNAME, TABLENAME,  Software Man,Product Name,Version Number,Part Number,Edition,Invoice Number

 

 

the spreadsheet can change so if there were 5 columns then invoice number would not show

 

I hope I make sense

 

 

 

 

 

Link to comment
Share on other sites

I will try and make this a bit easier to understand

 

My loop

 

foreach ($_POST['textbox'] as $datanumcolumns=>$datadownboxValue){
 $test = "exec importspreadsheet " . "'" . $newfilename . "'," ."'" .$table_name."'," ."'" .$datadownboxValue."' ";
 echo $test; 
 //echo "Textbox value" .$datanumcolumns. " has a value of " .$datadownboxValue. " "?><br /><?php
}

 

creates

 

exec importspreadsheet 'Synergy_SARnew.csv','newtable','Software Man'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Product Name'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Version Number'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Part Number'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Edition'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Invoice Number'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Supplier'
exec importspreadsheet 'Synergy_SARnew.csv','newtable','Purchasing Officer'

 

when I want it to loop through and create

exec importspreadsheet 'Synergy_SARnew.csv','newtable','Software Man','Product Name','Version Number','Part Number','Edition','Invoice Number','Supplier','Purchasing Officer'


hope this is more meaningful

 

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.