Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL2012-Split Functions and Columns

$
0
0
Hi ,
I am working in SQL-2012
I want to create a SP which Except Single Parameter as String and Split it in multiple Rows ,

Where Ever New Function comes in Paratemter It should Come in Seperate Rows and if Some Operator comes between Function then It should come in Seperate Column .

/* IF I EXECUTE MY SP WITH INPUT PARAMETRA AS EXEC MY_SP 'FUNCTION_1(COLA),FUNCTION_1(COLJ)+20,FUNCTION_1(COLJ)+20*30,FUNCTION_3(COLA,COLB), FUNCTION_4(COLX,COLY,COLZ)-FUNCTION_1(COLB),FUNCTION_19(COLD,COLD1)*FUNCTION_3(COLD,COLE)+11+FUNCTION_2(COLF)' THEN OUTPUT SHOULD COME IN BELOW FORMAT */ DECLARE @OUTPUT TABLE (FUN_NAME VARCHAR(100),COL_ONE VARCHAR(100),COL_TWO VARCHAR(100),COL_THREE VARCHAR(100),COL_FOUR VARCHAR(100), OPERATOR1 VARCHAR(10),VAL1 FLOAT,OPERATOR2 VARCHAR(10),VAL2 FLOAT) INSERT INTO @OUTPUT SELECT 'FUNCTION_1','COLA','','','','','','','' UNION ALL SELECT 'FUNCTION_1','COLJ','','','','+','20','','' UNION ALL SELECT 'FUNCTION_1','COLJ','','','','+','20','*','30' UNION ALL SELECT 'FUNCTION_3','COLA','COLB','','','','','','' UNION ALL SELECT 'FUNCTION_4','COLX','COLY','COLZ','','-','','','' UNION ALL SELECT 'FUNCTION_1','COLB','','','','','','','' UNION ALL SELECT 'FUNCTION_19','COLD','COLD1','','','*','','','' UNION ALL SELECT 'FUNCTION_3','COLD','COLE','','','+','11','+','' UNION ALL SELECT 'FUNCTION_2','COLF','','','','','','','' SELECT * FROM @OUTPUT /*
Second Example : IF I EXECUTE MY SP WITH INPUT PARAMETRA AS EXEC MY_SP 'FUNCTION_19(COLF,COLG),FUNCTION_19(COLD,COLD1)+FUNCTION_3(COLD,COLE)-FUNCTION_2(COLF)' THEN OUTPUT SHOULD COME IN BELOW FORMAT */ DECLARE @OUTPUT TABLE (FUN_NAME VARCHAR(100),COL_ONE VARCHAR(100),COL_TWO VARCHAR(100),COL_THREE VARCHAR(100),COL_FOUR VARCHAR(100), OPERATOR1 VARCHAR(10),VAL1 FLOAT,OPERATOR2 VARCHAR(10),VAL2 FLOAT) INSERT INTO @OUTPUT SELECT 'FUNCTION_19','COLF','COLG','','','','','','' UNION ALL SELECT 'FUNCTION_19','COLD','COLD1','','','+','','','' UNION ALL SELECT 'FUNCTION_3','COLD','COLE','','','-','','','' UNION ALL SELECT 'FUNCTION_2','COLF','','','','','','','' SELECT * FROM @OUTPUT

note : Function could have any Name(not necessary start with "Function_") create by Dev team
HELP ?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>