Manikyam Posted September 27, 2015 Report Posted September 27, 2015 neeku already 'work' value undi kada, appudu neeku 4 kavala kotta work value vesi? ante, neeku unna work value tho kalipi, extra 10 monday work 5 4 11 tuesday work 5 4 19 wednesday work 5 4 55 thursday work 5 4 42 friday work 5 4 ani kavala? ur explanantion
sqlhelp Posted September 27, 2015 Author Report Posted September 27, 2015 neeku already 'work' value undi kada, appudu neeku 4 kavala kotta work value vesi? ante, neeku unna work value tho kalipi, extra 10 monday work 5 4 11 tuesday work 5 4 19 wednesday work 5 4 55 thursday work 5 4 42 friday work 5 4 ani kavala? No no work value ledhu nenu final table ela untunda vesa indaka Work value 5 and sort valu would be 3 after adding frm previous value 2 Basic ga ah sort value oka oka row ki okola undi
andhravodu Posted September 28, 2015 Report Posted September 28, 2015 No no work value ledhu nenu final table ela untunda vesa indaka Work value 5 and sort valu would be 3 after adding frm previous value 2 Basic ga ah sort value oka oka row ki okola undi ee method pani chestundi. insert tho ee query try cheyi. 1 row vastundi kabatti cartesian join problem undadu with maxval as( select max(sort) + 1 sortval from <table> ) select id, name, 'work' as fieldname, 5 as value, maxval.sortval from <table>, maxval Where (table).fieldname = 'today Edit: where clause petta, filtering cheyataniki, otherwise, 10 rows insert instead of expected 5
sqlhelp Posted September 28, 2015 Author Report Posted September 28, 2015 What did u try about it so far man.. tell.. hi this is what i came up with declare @sortval int set @sortval = (select max(sort) from table) + 1 insert into table(ID,Name,Value,Sort) select mt.ID,'work',5,@sortval from maintable mt where mt.ID not in( select m.ID from maintable m join table t on t.ID = m.ID where t.name = 'work' ) kani max use chesthe it is using by default max num in that sort column for all columns but na situation for each name value the sort value is different like example monday has 3 different field names friday has 10 different fieldnames so sort value insert chesaka monday ki 4 (3+1) and friday ki 11 (10+1) but with max by default highest max value of that column like 10 + 1 cheshtundi even for monday row confusing ga undi koncham
sqlhelp Posted September 28, 2015 Author Report Posted September 28, 2015 ee method pani chestundi. insert tho ee query try cheyi. 1 row vastundi kabatti cartesian join problem undadu with maxval as( select max(sort) + 1 sortval from <table> ) select id, name, 'work' as fieldname, 5 as value, maxval.sortval from <table>, maxval Where (table).fieldname = 'today Edit: where clause petta, filtering cheyataniki, otherwise, 10 rows insert instead of expected 5 I tried this max highest value add avthundi for all rows but naku depending on highest sort value for each different name ki + 1 cheyali
andhravodu Posted September 28, 2015 Report Posted September 28, 2015 I tried this max highest value add avthundi for all rows but naku depending on highest sort value for each different name ki + 1 cheyali so, every individual fieldnames ki unna existing value ki +1 ravali. partition by vadi individual fields ki max tecchi cheyi with maxval as( select field, maxsort+1 as sortval from ( select fieldname field, MAX(sort) OVER (PARTITION BY fieldname) maxsort from <table> ) ) select id, name, fieldname, 5 as value, maxval.sortval from <table>, maxval where fieldname = maxval.field; -- value 5 constant ga force chestunna nee req prakaram
vizagpower Posted September 28, 2015 Report Posted September 28, 2015 again Rofl man.. Dude called you many times this weekend
sqlhelp Posted September 29, 2015 Author Report Posted September 29, 2015 so, every individual fieldnames ki unna existing value ki +1 ravali. partition by vadi individual fields ki max tecchi cheyi with maxval as( select field, maxsort+1 as sortval from ( select fieldname field, MAX(sort) OVER (PARTITION BY fieldname) maxsort from <table> ) ) select id, name, fieldname, 5 as value, maxval.sortval from <table>, maxval where fieldname = maxval.field; -- value 5 constant ga force chestunna nee req prakaram Thank you man
Recommended Posts