select - Selecting fields by ordinal_Number, adapting MS-SQL-Code to MySQL -


i need extract fieldnames great number of tables, having same structure unfortunately not same field names. varying. need check ordinal position of fields required, because tables have same order of fields. newbie on mysql.

my ms-sql-guru gave me 'blueprint' of procedure want via sys.columns, cannot adapt mysql. want have resulting select statement handover next batch of commands.

here have done far:

create definer=`root2`@`%` procedure `sp_getcolsfromschema`(in lsid int) begin set @cols=''; set @tbls = concat('mytableprefix_', lsid);  select      @cols = @cols + column_name + ', '     information_schema.columns     table_name = @tbls collate utf8_unicode_ci         , table_schema = 'myschema'         , ordinal_position in (2 , 4, 5, 7);  set @cols = left(@cols, length(@cols)-1);  set @str = 'select ' + @cols + ' ' + @tbls +';'; prepare stmt @str; execute stmt; end 

when calling procedure error 1064 hint "... check syntax near '0' @ line 1" confusing me.

can please me on right track?


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -