Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My data Table contains the shown below table:

RT	val	dt
RT1       	995	2015-09-09
RT2       	243	NULL
RT3       	662	2015-09-09
RT1       	NULL	NULL
RT1       	NULL	NULL
RT3       	662	2015-09-09
RT3       	NULL	NULL


SELECT Statement is:

SELECT * FROM [dbo].[Table_2]


I Want all the cells with NULL values to show the corresponding values from the above rows as shown below:

RT	val	dt
RT1       	995	9/9/2015
RT2       	243	NULL
RT3       	662	9/9/2015
RT1       	995	9/9/2015
RT1       	995	9/9/2015
RT3       	662	9/9/2015
RT3       	662	9/9/2015


How can we acheive this?

Thanks.
Posted

1 solution

You need to put this code in to proC ( pre Compiler for SQL C - Embedded SQL like Oracle proC)

EXEC SQL
BEGIN
int j;
for (int i = 1; i<=table_2.size; i++) {
SELECT RT, val, dt INTO varRT[i], varval[i], vardt[i] from [dbo].[Table_2];
}

for (i = 1; i<=table_2.size - 1; i++) {
for (j = i+1; table_2.size; j++) {
if (varval[j] == NULL) varval[j] = varval[i];
if (vardt[j] == NULL ) vardt[j] = vardt[i];
}
}

END EXEC
 
Share this answer
 
Comments
ZohaibRazaTheDProgrammer 14-Sep-15 13:05pm    
I am sorry I am a beginner. Please explain how to use this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900