SQL Server ,Insert values based on values

Posted by Raja_89 under Sql Server on 6/6/2014 | Points: 10 | Views : 424 | Status : [Member] | Replies : 1
Hi
I having fields as try1,try2,try3.. upto try24
The condition if i choose try values should be inserted in Try1
The condition if 2 choose try values should be inserted in Try2
..etc

Regards




Responses

Posted by: Sheonarayan on: 6/6/2014 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Use switch statement for the try value and frame dynamic query.

string sql = string.Empty;
switch (try)
{
case 1:
sql = "insert into try1 values ('myvalue');
break;
case 2:
sql = "insert into try2 values ('myvalue');
break;
// further case statements
}

Above code should be good but you can even refine the sql string value by not repeating the insert statement but just saving the try field name and its value.

Hope this helps.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response