Avatar of Brian
Brian
Flag for United States of America asked on

Add DateTime based on a value from DropDownList

Hello Experts,

I have a web form that I need help with. I would like to be able to add the current DateTime to a field in my DB if a DropDownList value is selected as "Closed". If the value from the DropDownList value is NOT "Closed" then do not add DateTime to field in DB.

Please see my current CodeBehind below. There is no TextBox for the Completion Date. I somehow need to programatically put that value into my DB basd on the value from the DropDownList if it's "Closed".

CodeBehind:
protected void btnModifyTicket_Click(object sender, EventArgs e)
    {
        int TicketID = Convert.ToInt32(Request.QueryString["tkt_id"].ToString());

        if (Page.IsValid) // make sure all fields have data before Inserting to DB.
        {
            if (fuAttachFile.HasFile)  // a file has been uploaded
            {
                //Make sure we are dealing a .pdf file only
                string extension = Path.GetExtension(fuAttachFile.PostedFile.FileName).ToLower();
                string MIMEType = null;

                switch (extension)
                {
                    case ".pdf":
                        MIMEType = "application/pdf";
                        break;
                    case ".doc":
                        MIMEType = "application/msword";
                        break;
                    case ".xls":
                        MIMEType = "application/vnd.ms-excel";
                        break;
                    case ".txt":
                        MIMEType = "text/plain";
                        break;
                    case ".png":
                        MIMEType = "image/png";
                        break;
                    case ".jpg":
                        MIMEType = "image/jpeg";
                        break;
                    case ".jpeg":
                        MIMEType = "image/jpeg";
                        break;
                    case ".vsd":
                        MIMEType = "application/vnd.visio";
                        break;
                    default:
                        lblFileTypeError.Visible = true;
                        lblFileTypeError.Text = "PDF files only.";
                        return;
                }

                string filename = fuAttachFile.PostedFile.FileName.Split(new char[] { '\\' }).Last();
                int fileSize = fuAttachFile.PostedFile.ContentLength;

                // Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
                if ((fileSize < 1048576))
                {
                    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMDB"].ConnectionString);

                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = "ModifyTicket";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection = conn;

                    // Load PDF InputStream into Byte array
                    byte[] imageBytes = new byte[fuAttachFile.PostedFile.InputStream.Length + 1];
                    fuAttachFile.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);

                    cmd.Parameters.AddWithValue("@tkt_id", SqlDbType.Int).Value = TicketID;
                    cmd.Parameters.AddWithValue("@usr_req_chg_id", SqlDbType.Int).Value = ddlUserRequestingChange.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@req_typ_id", SqlDbType.Int).Value = ddlRequestType.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@com_id", SqlDbType.Int).Value = ddlCompany.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@sts_id", SqlDbType.Int).Value = ddlStatusType.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@ownr_id", SqlDbType.Int).Value = ddlTicketOwner.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@tkt_desc", SqlDbType.VarChar).Value = txtTicketDesc.Text;
                    cmd.Parameters.AddWithValue("@tkt_resolution", SqlDbType.VarChar).Value = txtTicketResolution.Text;
                    cmd.Parameters.AddWithValue("@tkt_file", SqlDbType.Image).Value = imageBytes;
                    cmd.Parameters.AddWithValue("@tkt_filename", SqlDbType.VarChar).Value = filename;
                    cmd.Parameters.AddWithValue("@tkt_mime", SqlDbType.VarChar).Value = MIMEType;
                    cmd.Parameters.AddWithValue("@tkt_size", SqlDbType.VarChar).Value = fileSize;

                    if (string.IsNullOrEmpty(txtCompletionDate.Text))
                    {
                        cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = txtCompletionDate.Text;
                    }

                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                    }

                    catch (Exception ex)
                    {
                        lblInsertError.Visible = true;
                        lblInsertError.Text = ("Error on insert: " + ex.Message.ToString());
                    }

                    finally
                    {
                        Response.Redirect("index.aspx");
                        conn.Close();
                    }
                }

                else
                {
                    lblFileSize.Visible = true;
                    lblFileSize.Text = "File size must be 1MB or smaller.";
                }
            }
            else  // no file has been uploaded, we only need to update txtPhysicalDateCompleted
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMDB"].ConnectionString);

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "ModifyTicket";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;

                byte[] imageBytes = new byte[1];

                cmd.Parameters.AddWithValue("@tkt_id", SqlDbType.Int).Value = TicketID;
                cmd.Parameters.AddWithValue("@usr_req_chg_id", SqlDbType.Int).Value = ddlUserRequestingChange.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@req_typ_id", SqlDbType.Int).Value = ddlRequestType.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@com_id", SqlDbType.Int).Value = ddlCompany.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@sts_id", SqlDbType.Int).Value = ddlStatusType.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@ownr_id", SqlDbType.Int).Value = ddlTicketOwner.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@tkt_desc", SqlDbType.VarChar).Value = txtTicketDesc.Text;
                cmd.Parameters.AddWithValue("@tkt_resolution", SqlDbType.VarChar).Value = txtTicketResolution.Text;
                cmd.Parameters.AddWithValue("@tkt_file", SqlDbType.Image).Value = imageBytes;
                cmd.Parameters.AddWithValue("@tkt_filename", SqlDbType.VarChar).Value = "";
                cmd.Parameters.AddWithValue("@tkt_mime", SqlDbType.VarChar).Value = "application/octet-stream";
                cmd.Parameters.AddWithValue("@tkt_size", SqlDbType.VarChar).Value = 0;

                if (string.IsNullOrEmpty(txtCompletionDate.Text))
                {
                    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = txtCompletionDate.Text;
                }

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }

                catch (Exception ex)
                {
                    lblInsertError.Visible = true;
                    lblInsertError.Text = ("Error on insert: " + ex.Message.ToString());
                }

                finally
                {
                    Response.Redirect("index.aspx");
                    conn.Close();
                }
            }
        }
    }

Open in new window

ASP.NET.NET ProgrammingC#

Avatar of undefined
Last Comment
Rouchie

8/22/2022 - Mon
SOLUTION
kaufmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rouchie

Rather than do this in ASP.NET, you can do it directly in the database.  For example, when the field is set to 'closed', as part of the update statement use the GetDate() function (that's in SQL):

Declare d datetime
SET d = GetDate()
UPDATE myTable SET status = 'closed', completionDate = d WHERE ID = someID
Brian

ASKER
@kaufmed,

There is no TextBox Control. I need to programatically add the DateTime if the value from the DropDownList is "Closed". If it is then I need to add DateTime to the field in the DB.

I tried to add your code but when I add it I'm receiving a red line with the following error message.

Red Line Error Message:
Operator '!=' cannot be applied to operands of type 'System.Web.UI.WebControls.ListItem' and 'string'
Brian

ASKER
@Rouchie,

Can you show me how to perform that in the DB? Please see my current Stored Procedure that I'm using now for the Update.

Also, the field that I need to add the DateTime into will not always have the value 'Closed' assigned to it. The user may change that value on the webform to 4 other options so not sure how this can be done within SQL.

ALTER PROCEDURE [dbo].[ModifyTicket]

(
@tkt_id int,
@usr_req_chg_id int,
@req_typ_id int,
@com_id int,
@sts_id int,
@ownr_id int,
@tkt_desc varchar(max),
@tkt_resolution varchar(max),
@tkt_cmpl_dt datetime,
@tkt_file image,
@tkt_filename varchar(50),
@tkt_mime varchar(100),
@tkt_size varchar(50)
)

AS

UPDATE Tickets
      SET usr_req_chg_id = @usr_req_chg_id,
	        req_typ_id = @req_typ_id,
			com_id = @com_id,
			sts_id = @sts_id,
			ownr_id = @ownr_id,
			tkt_desc = @tkt_desc,
			tkt_resolution = @tkt_resolution,
			tkt_cmpl_dt = @tkt_cmpl_dt,
            tkt_file = case when DATALENGTH(@tkt_file) <= 4 then tkt_file else @tkt_file end,
            tkt_filename = isnull(nullif(@tkt_filename,''), tkt_filename),
            tkt_mime = isnull(nullif(@tkt_mime,'application/octet-stream'), tkt_mime),
            tkt_size = isnull(nullif(@tkt_size,0), tkt_size)
      WHERE tkt_id = @tkt_id

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Rouchie

Sure - just make sure you change the name of the column I've guess at below to your actual data column name:

ALTER PROCEDURE [dbo].[ModifyTicket]

(
@tkt_id int,
@usr_req_chg_id int,
@req_typ_id int,
@com_id int,
@sts_id int,
@ownr_id int,
@tkt_desc varchar(max),
@tkt_resolution varchar(max),
@tkt_cmpl_dt datetime,
@tkt_file image,
@tkt_filename varchar(50),
@tkt_mime varchar(100),
@tkt_size varchar(50)
)

AS

DECLARE @today DATETIME /* <-- my addition */
SET @today = GetDate()  /* <-- my addition */

UPDATE Tickets
      SET usr_req_chg_id = @usr_req_chg_id,
	        req_typ_id = @req_typ_id,
			com_id = @com_id,
			sts_id = @sts_id,
			ownr_id = @ownr_id,
			tkt_desc = @tkt_desc,
			tkt_resolution = @tkt_resolution,
			tkt_cmpl_dt = @tkt_cmpl_dt,
            tkt_file = case when DATALENGTH(@tkt_file) <= 4 then tkt_file else @tkt_file end,
            tkt_filename = isnull(nullif(@tkt_filename,''), tkt_filename),
            tkt_mime = isnull(nullif(@tkt_mime,'application/octet-stream'), tkt_mime),
            tkt_size = isnull(nullif(@tkt_size,0), tkt_size),
            [DateColumnNameHere] = @today  /* <-- my addition */
      WHERE tkt_id = @tkt_id

Open in new window

Brian

ASKER
@Rouchie,

Sorry, I don't understand what I need to put for [DateColumnNameHere].

Also, if i'm using the (getDate()) function in SQL do I still need to declare the @tkt_cmpl_dt on top along with the Update procedure below?
Rouchie

I assumed that you had a field in your Tickets database table that held a date value.  Am I wrong with that guess?   If not, then you simply replace DateColumnNameHere with the column name that holds the date.

If I am wrong, please let me know (in laymans terms - assuming I don't know anything about your app!) where the date needs to go!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
kaufmed

Red Line Error Message:
Operator '!=' cannot be applied to operands of type 'System.Web.UI.WebControls.ListItem' and 'string'
Add "Value" to that line:

if (theDdlInQuestion.SelectedItem.Value != "Closed")

Open in new window

Brian

ASKER
>> I assumed that you had a field in your Tickets database table that held a date value.  Am I wrong with that guess?

Yes, the name of the field that I need to add the (getdate()) function to is called "tkt_cmpl_dt". I only need to add the (getdate()) function to "tkt_cmpl_dt" if the value of "sts_id" equals "Closed" or "72" which "72" represents "Closed" in the DB.
Rouchie

Okay that's a bit trickier but still fine.  We do the logic testing earlier.

ALTER PROCEDURE [dbo].[ModifyTicket]

(
@tkt_id int,
@usr_req_chg_id int,
@req_typ_id int,
@com_id int,
@sts_id int,
@ownr_id int,
@tkt_desc varchar(max),
@tkt_resolution varchar(max),
@tkt_cmpl_dt datetime,
@tkt_file image,
@tkt_filename varchar(50),
@tkt_mime varchar(100),
@tkt_size varchar(50)
)

AS


DECLARE @today DATETIME 

IF @sts_id = 72
	SET @today = GetDate() 
ELSE
	SET @today = NULL

UPDATE Tickets SET 
	usr_req_chg_id = @usr_req_chg_id,
	req_typ_id = @req_typ_id,
	com_id = @com_id,
	sts_id = @sts_id,
	ownr_id = @ownr_id,
	tkt_desc = @tkt_desc,
	tkt_resolution = @tkt_resolution,
	tkt_cmpl_dt = @tkt_cmpl_dt,
	tkt_file = case when DATALENGTH(@tkt_file) <= 4 then tkt_file else @tkt_file end,
	tkt_filename = isnull(nullif(@tkt_filename,''), tkt_filename),
	tkt_mime = isnull(nullif(@tkt_mime,'application/octet-stream'), tkt_mime),
	tkt_size = isnull(nullif(@tkt_size,0), tkt_size),
	tkt_cmpl_dt = @today  /* <-- my addition */
WHERE
	(tkt_id = @tkt_id)

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Brian

ASKER
@kaufmed,

That did not work either. No errors this time but when I selected the value "Closed" from the DropDownList it added the value NULL instead of the DateTime. Please see my codebehind below for the Click Event. Notice though that I do not have a TextBox Control so I added System.DateTime.Now in it's place.

The only other thing I can think of is that "Closed" represents 72 in the DB for that value.

protected void btnModifyTicket_Click(object sender, EventArgs e)
    {
        int TicketID = Convert.ToInt32(Request.QueryString["tkt_id"].ToString());

        if (Page.IsValid) // make sure all fields have data before Inserting to DB.
        {
            if (fuAttachFile.HasFile)  // a file has been uploaded
            {
                //Make sure we are dealing a .pdf file only
                string extension = Path.GetExtension(fuAttachFile.PostedFile.FileName).ToLower();
                string MIMEType = null;

                switch (extension)
                {
                    case ".pdf":
                        MIMEType = "application/pdf";
                        break;
                    case ".doc":
                        MIMEType = "application/msword";
                        break;
                    case ".xls":
                        MIMEType = "application/vnd.ms-excel";
                        break;
                    case ".txt":
                        MIMEType = "text/plain";
                        break;
                    case ".png":
                        MIMEType = "image/png";
                        break;
                    case ".jpg":
                        MIMEType = "image/jpeg";
                        break;
                    case ".jpeg":
                        MIMEType = "image/jpeg";
                        break;
                    case ".vsd":
                        MIMEType = "application/vnd.visio";
                        break;
                    default:
                        lblFileTypeError.Visible = true;
                        lblFileTypeError.Text = "PDF files only.";
                        return;
                }

                string filename = fuAttachFile.PostedFile.FileName.Split(new char[] { '\\' }).Last();
                int fileSize = fuAttachFile.PostedFile.ContentLength;

                // Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
                if ((fileSize < 1048576))
                {
                    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMDB"].ConnectionString);

                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = "ModifyTicket";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection = conn;

                    // Load PDF InputStream into Byte array
                    byte[] imageBytes = new byte[fuAttachFile.PostedFile.InputStream.Length + 1];
                    fuAttachFile.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);

                    cmd.Parameters.AddWithValue("@tkt_id", SqlDbType.Int).Value = TicketID;
                    cmd.Parameters.AddWithValue("@usr_req_chg_id", SqlDbType.Int).Value = ddlUserRequestingChange.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@req_typ_id", SqlDbType.Int).Value = ddlRequestType.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@com_id", SqlDbType.Int).Value = ddlCompany.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@sts_id", SqlDbType.Int).Value = ddlStatusType.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@ownr_id", SqlDbType.Int).Value = ddlTicketOwner.SelectedItem.Value;
                    cmd.Parameters.AddWithValue("@tkt_desc", SqlDbType.VarChar).Value = txtTicketDesc.Text;
                    cmd.Parameters.AddWithValue("@tkt_resolution", SqlDbType.VarChar).Value = txtTicketResolution.Text;
                    cmd.Parameters.AddWithValue("@tkt_file", SqlDbType.Image).Value = imageBytes;
                    cmd.Parameters.AddWithValue("@tkt_filename", SqlDbType.VarChar).Value = filename;
                    cmd.Parameters.AddWithValue("@tkt_mime", SqlDbType.VarChar).Value = MIMEType;
                    cmd.Parameters.AddWithValue("@tkt_size", SqlDbType.VarChar).Value = fileSize;

                    if (ddlStatusType.SelectedItem.Value != "Closed")
                    {
                        cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = DBNull.Value;
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = System.DateTime.Now;
                    }


                    //if (string.IsNullOrEmpty(txtCompletionDate.Text))
                    //{
                    //    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = DBNull.Value;
                    //}
                    //else
                    //{
                    //    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = txtCompletionDate.Text;
                    //}

                    try
                    {
                        conn.Open();
                        cmd.ExecuteNonQuery();
                    }

                    catch (Exception ex)
                    {
                        lblInsertError.Visible = true;
                        lblInsertError.Text = ("Error on insert: " + ex.Message.ToString());
                    }

                    finally
                    {
                        Response.Redirect("index.aspx");
                        conn.Close();
                    }
                }

                else
                {
                    lblFileSize.Visible = true;
                    lblFileSize.Text = "File size must be 1MB or smaller.";
                }
            }
            else  // no file has been uploaded, we only need to update txtPhysicalDateCompleted
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMDB"].ConnectionString);

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "ModifyTicket";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;

                byte[] imageBytes = new byte[1];

                cmd.Parameters.AddWithValue("@tkt_id", SqlDbType.Int).Value = TicketID;
                cmd.Parameters.AddWithValue("@usr_req_chg_id", SqlDbType.Int).Value = ddlUserRequestingChange.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@req_typ_id", SqlDbType.Int).Value = ddlRequestType.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@com_id", SqlDbType.Int).Value = ddlCompany.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@sts_id", SqlDbType.Int).Value = ddlStatusType.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@ownr_id", SqlDbType.Int).Value = ddlTicketOwner.SelectedItem.Value;
                cmd.Parameters.AddWithValue("@tkt_desc", SqlDbType.VarChar).Value = txtTicketDesc.Text;
                cmd.Parameters.AddWithValue("@tkt_resolution", SqlDbType.VarChar).Value = txtTicketResolution.Text;
                cmd.Parameters.AddWithValue("@tkt_file", SqlDbType.Image).Value = imageBytes;
                cmd.Parameters.AddWithValue("@tkt_filename", SqlDbType.VarChar).Value = "";
                cmd.Parameters.AddWithValue("@tkt_mime", SqlDbType.VarChar).Value = "application/octet-stream";
                cmd.Parameters.AddWithValue("@tkt_size", SqlDbType.VarChar).Value = 0;

                if (ddlStatusType.SelectedItem.Value != "Closed")
                {
                    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = System.DateTime.Now;
                }


                //if (string.IsNullOrEmpty(txtCompletionDate.Text))
                //{
                //    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = DBNull.Value;
                //}
                //else
                //{
                //    cmd.Parameters.AddWithValue("@tkt_cmpl_dt", SqlDbType.DateTime).Value = txtCompletionDate.Text;
                //}

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }

                catch (Exception ex)
                {
                    lblInsertError.Visible = true;
                    lblInsertError.Text = ("Error on insert: " + ex.Message.ToString());
                }

                finally
                {
                    Response.Redirect("index.aspx");
                    conn.Close();
                }
            }
        }
    }

Open in new window

Rouchie

You're logic is really a database integrity rule, so you might as well save time and just use the stored procedure, to save ASP.NET messing about with the logic!
Brian

ASKER
@Rouchie,

Ok, based on the solution you supplied in post 38713015 i'm not sure that will work. You have the value sts_id equal to NULL if the value is not 72. But remember I will have up to 4 other values to add. So what do I do if the value is 70, 71, 73 and or 75? It's not jsut 72 only.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Brian

ASKER
@kaufmed,

Your solution worked. I just had to remove "the value Closed" and assign the value "Closed" to the value of "72" :)
Rouchie

You can use a CASE statement to set the @today value based on the value of  sts_id.
Let me know all the possibilities and I'll write the CASE statement in the procedure
Brian

ASKER
@Rouchie,

Can you show me? It would be nice to have this work either via code or DB.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Rouchie

Yes I will show you, but first, I need to know the possibilities that your logic can include.  I could perhaps fathom this from C#, but I'd prefer it in plain English so that I don't make any mistakes please!

e.g.
value sts_id equal to NULL if the value is not 72.
value sts_id equal to ______ if value is _____
etc
Brian

ASKER
sts_id possible values:

70 = -- Select --
71 = Open
72 = Closed
73 = Locked
Rouchie

Just need numbers and column names please, so...

If sts_id = 72 Then tkt_cmpl_dt = (today's date)
If sts_id = ____ Then tkt_cmpl_dt = ____

if that's okay?!?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Brian

ASKER
If sts_id = 72 then tkt_cmpl_dt = (todays date)

if sts_id = any other value then NULL needs to be assigned to tkt_cmpl_dt.

Thanks again Rouchie, even though kaufmed's solution worked in Code I would also like to have it work in SQL and then I can share points between you both.
ASKER CERTIFIED SOLUTION
Rouchie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Brian

ASKER
@Rouchie,

should @today be @tkt_cmpl_dt instead? How are you adding the DateTime to field tkt_cmpl_dt if the sts_id value is 72?
Rouchie

Look at the line before WHERE

That is where the value placed in the @today variable is saved into the tkt_cmpl._id column
Your help has saved me hundreds of hours of internet surfing.
fblack61