Solved

Sql Server column vakue insert

Posted on 2011-10-01
10
181 Views
Last Modified: 2012-08-13
Hi,

In my sql server table these are the columns:

ID                 CategoryID         Description                            code
Q101           cat1                    VLC - 001 Example1              VLC - 001
Q102           cat1                    VLC - 002 Example1              VLC - 002
Q103            cat2                   PAY - 001 Example1              PAY - 001

When the user input data into this table:
(1) I wanted to generate this code depending on the CategoryID i.e. For Cat1 VLC - 001, VLC -002 and so forth
(2) For each row for the description I need to prefix the  respective code for each row they insert into table.

This data input not through a application or anything like that but they will do it in the management studio so I wanted to do this in table level in the sql server. Can I create a function and attach to this column so every time the user add a new row and will use this function to generate next available code for that row and also prefix this description as well.

Any help would very greatly appreciated....
0
Comment
Question by:ube100
  • 6
  • 4
10 Comments
 
LVL 6

Accepted Solution

by:
billfusion earned 250 total points
ID: 36897214
The easiest would be to only allow the categoryID to be entered by the user then use calculated values to insert into the rest of the columns.  Your best bet is to use a stored procedure that you pass it the ID and category id.  The procedure then sets up the proper strings either based on a lookup table, if you have many category type, or hard coded in the procedure.  The procedure then insert the proper values in the table.  The stored procedure also need to lookup the max number of records already in a table to find the correct value to append.

Calculate the Code first, then use the code to enter into the description.
0
 

Author Comment

by:ube100
ID: 36897523
This is not from a application but this is rather from a data entry by an admin staff using sql server management studio so can I still be able to call the stored procedure? If yes then how?
0
 
LVL 6

Expert Comment

by:billfusion
ID: 36897836
In that case triggers may be more appropriate.  You can find a short description about creating  triggers here:
http://msdn.microsoft.com/en-us/library/ms189799.aspx
0
 
LVL 6

Expert Comment

by:billfusion
ID: 36897839
A better introduction about triggers can be found here:
http://www.sqlteam.com/article/an-introduction-to-triggers-part-i
0
 
LVL 6

Expert Comment

by:billfusion
ID: 36897842
Can you include a sample of the code that you're trying to get working?
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 6

Expert Comment

by:billfusion
ID: 36897851
The last comment was an accident.  Please disregard it.
0
 

Author Comment

by:ube100
ID: 36897896
These are the two tables in question:

CREATE TABLE [sysdba].[CATEGORY](
      [CATEGORYID] [char](12) NOT NULL,
      [CREATEUSER] [char](12) NULL,
      [CREATEDATE] [datetime] NULL,
      [MODIFYUSER] [char](12) NULL,
      [MODIFYDATE] [datetime] NULL,
      [CATEGORYNAME] [varchar](55) NULL
) ON [PRIMARY]

CREATE TABLE [sysdba].[CALLOUTCOMES](
      [CALLOUTCOMESID] [char](12) NOT NULL,
      [CATEGORYID] [char](12) NOT NULL,
      [CREATEUSER] [char](12) NULL,
      [CREATEDATE] [datetime] NULL,
      [MODIFYUSER] [char](12) NULL,
      [MODIFYDATE] [datetime] NULL,
      [OUTCOMES] [varchar](80) NULL,
      [CALLOUTCOMECODE] [varchar](32) NULL
) ON [PRIMARY]

When they adding a new row to CALLOUTCOMES table they will use the categoryid from the category table and depending on the category we need to insert a appropriate code for CALLOUTCOMECODE column and then append that code as a prefix for the description which user entered.  i.e.  VLC - 001 Example1              VLC - 001

If we have to do this via a trigger then how we go about it please?
0
 
LVL 6

Expert Comment

by:billfusion
ID: 36898329
Can you list some row from Category, and what the user will enter in calloutcome?  is the value VLC-001 retrieved from category?  Or is it part of that code that's retrieved from category?
0
 

Author Comment

by:ube100
ID: 36900365
Category:

Q6UJ9A0RCBTK      VLC Inquires
Q6UJ9A0RCBTL      Payments

Calloutcomes:

Q6UJ9A0RCBU9      Q6UJ9A0RCBTK      U6UJ9A0000AF      2011-09-12 12:07:17.473      U6UJ9A0000AF      2011-09-12 12:07:17.473      VLC - 001 Navigation of te website      VLC - 001

Q6UJ9A0RCBUR      Q6UJ9A0RCBTL      U6UJ9A0000AF      2011-09-12 12:38:21.020      U6UJ9A0000AF      2011-09-12 12:38:21.020      PAY - 001 Monthly instalment paid      PAY - 001

VLC will represent VLC Inquiry category and anything come under that category will be VLC -001 for the first one and VLC - 002 for the 2nd one and so forth.
 
0
 

Author Closing Comment

by:ube100
ID: 37337670
That didn't help solve my issue.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now