SQL SERVER CHECKBOX VALUE

The following code inserts "1" or "0" into my DB.   I need help with regard to inserting a specific value ie.  if the checkbox is checked it would insert "Eqpt Swap" and if left unchecked
the value would be NULL or "No Swap".   My DB column for "MM" is currently setup as "NVarChar".  

cmd.CommandText = ("INSERT  into Delays VALUES (@Dates,@Ship,@Station,@GT,@Log,@Inbd,@Otbd,@Dep,@Ground,@Code,@Time,@Code1,@Time1,@Wake,@Captain,@RON,@Ck,@Hist,@Call,@MM,@RB,@Tech,@Lead,@Reason,@Comment,@ATA,@DelayReason)");

Open in new window




Open in new window

cmd.Parameters.AddWithValue("@MM", (MM.Checked ? 1 : 0));
BOEING39Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
INSERT INTO Delays
Values (...,, CASE WHEN @MM = 1 THEN 'Eqpt Swap' ELSE 'No Swap' END, ...)
0
Tapan PattanaikSenior EngineerCommented:
Hi BOEING39 ,

This is an example:

insert into table
values (@ssn,@empid,@race,
CASE @description
WHEN 'deputy' THEN 'Y'
WHEN 'civilian' THEN 'N'
end
)
0
BOEING39Author Commented:
I am not sure of the placement of the code.   Please assist?

 
cmd.CommandText = ("INSERT  into Delays VALUES (@Dates,@Ship,@Station,@GT,@Log,@Inbd,@Otbd,@Dep,@Ground,@Code,@Time,@Code1,@Time1,@Wake,@Captain,@RON,@Ck,@Hist,@Call,...,, CASE WHEN @MM = 1 THEN 'Eqpt Swap' ELSE 'No Swap' END, ...,@RB,@Tech,@Lead,@Reason,@Comment,@ATA,@DelayReason)");

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Brian CroweDatabase AdministratorCommented:
In your commandtext
0
BOEING39Author Commented:
I am getting the following error with the code inserted as follows:

Error      Incorrect syntax near ','.  


cmd.CommandText = ("INSERT  into Delays VALUES (@Dates,@Ship,@Station,@RON,@Ck,@Hist,@Call,(...,,CASE WHEN @MM = 1 THEN 'Eqpt Swap' ELSE 'No Swap' END, ...),@RB,@Tech,@Lead,@Reason,@Comment,@ATA,@DelayReason)");

Open in new window

0
Brian CroweDatabase AdministratorCommented:
I think I had an extra comma in my example...post exactly what you're trying pls
0
BOEING39Author Commented:
Here is the entire code as revised that is producing the error:

 cmd.CommandText = ("INSERT  into Delays VALUES (@Dates,@Ship,@Station,@GT,@Log,@Inbd,@Otbd,@Dep,@Ground,@Code,@Time,@Code1,@Time1,@Wake,@Captain,@RON,@Ck,@Hist,@Call,(...,CASE WHEN @MM = 1 THEN 'Eqpt Swap' ELSE 'No Swap' END, ...),@RB,@Tech,@Lead,@Reason,@Comment,@ATA,@DelayReason)");

        cmd.Parameters.AddWithValue("@Dates", DateTime.Now);
        cmd.Parameters.AddWithValue("@Ship", Ship.SelectedValue);
        cmd.Parameters.AddWithValue("@Station", Station.Text);
        cmd.Parameters.AddWithValue("@GT", GT.Text);
        cmd.Parameters.AddWithValue("@Log", Log.Text);
        cmd.Parameters.AddWithValue("@Inbd", Inbd.Text);
        cmd.Parameters.AddWithValue("@Otbd", Otbd.Text);
        cmd.Parameters.AddWithValue("@Dep", Dep.Text);
        cmd.Parameters.AddWithValue("@Ground", Ground.Text);
        cmd.Parameters.AddWithValue("@Code", Code.SelectedValue);
        cmd.Parameters.AddWithValue("@Time", Time.Text);
        cmd.Parameters.AddWithValue("@Code1", Code1.SelectedValue);
        cmd.Parameters.AddWithValue("@Time1", Time1.Text);
        cmd.Parameters.AddWithValue("@Wake", Wake.SelectedValue);
        cmd.Parameters.AddWithValue("@Captain", Captain.SelectedValue);
        cmd.Parameters.AddWithValue("@RON", RON.SelectedValue);
        cmd.Parameters.AddWithValue("@Ck", Ck.SelectedValue);
        cmd.Parameters.AddWithValue("@Hist", HistCk.SelectedValue);
        cmd.Parameters.AddWithValue("@Call", Call.Text);
        cmd.Parameters.AddWithValue("@MM", (MM.Checked ? 1 : 0));
        cmd.Parameters.AddWithValue("@RB", RB.Text);
        cmd.Parameters.AddWithValue("@Tech", Tech.SelectedValue);
        cmd.Parameters.AddWithValue("@Lead", Lead.SelectedValue);
        cmd.Parameters.AddWithValue("@Reason", Reason.Text);
        cmd.Parameters.AddWithValue("@Comment", Comment.Text);
        cmd.Parameters.AddWithValue("@ATA", ATA.SelectedValue);
        cmd.Parameters.AddWithValue("@DelayReason", DelayReason.SelectedValue);
        
             
        cmd.ExecuteNonQuery();
        con.Close();

Open in new window

0
Brian CroweDatabase AdministratorCommented:
:-) The ellipses were just placeholders for the text I was too lazy to type out..


cmd.CommandText = ("INSERT  into Delays VALUES (@Dates,@Ship,@Station,@GT,@Log,@Inbd,@Otbd,@Dep,@Ground,@Code,@Time,@Code1,@Time1,@Wake,@Captain,@RON,@Ck,@Hist,@Call,(CASE WHEN @MM = 1 THEN 'Eqpt Swap' ELSE 'No Swap' END),@RB,@Tech,@Lead,@Reason,@Comment,@ATA,@DelayReason)");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BOEING39Author Commented:
Thanks very much.  Works fine now.  I appreciate the quick responses and follow-up.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.