Help In Auto Generating Item Code

Aug 28, 2007

Hi guys,

I am new to programming and sqlserver 2000. i use sql2000 as my database server...

I have a problem on auto-generating medicine codes. and i hope someone would help me with my script.

as you noticed i declared two variables (@id and @code). I am having a problem in generating @code... i would just like to create an autogenerated medicines_code from another field from another table (hosp_counter.counter_id)

here is how my medicines_code should look like ('MEDS34') "where 34 is from a counter_id in hosp_counter table...

but it only creates a medicines_code = 'M' (below is the result)

34(this is from counter_id)M(this is the autogenerated code)AUTOGENERATE11111010110012110010000000018/29/2007 11:29:46 AM1/1/19001/1/1900

here is my script in autogenerating medicine code...

set xact_abort on
begin transaction
declare @Code as varchar
select @Code =
(select 'MEDS' + CAST
(Counter_ID + 1 as varchar (50))
from Hosp_Counter where table_description = 'Medicines')
declare @ID as integer
select @ID = Counter_ID + 1
from Hosp_Counter
where table_description = 'Medicines'
select @ID
INSERT INTO Hosp_Medicines
(medicines_id,
medicines_code,
medicines_description,
medicines_specification,
medicines_genericname,
medicines_drugclass,
PhicCategory,
medpreparation,
medicines_prohibited,
medicines_trade,
medicines_NoneTrade,
medicines_taxable,
medicines_PhicCovered,
medicines_AmountCovered,
medicines_Discountable,
medicines_SmallUnit,
medicines_BigUnit,
medicines_AverageCostSmall,
medicines_AverageCostBig,
medicines_WeightedAverageCost,
medicines_weight,
medicines_conversion,
medicines_LowStockLevel,
medicines_OverStockLevel,
medicines_LowSalesReference,
AllowStat,
status,
CreateBy,
UpdateBy,
DeleteBy,
CreateDate,
UpdateDate,
DeleteDate)
VALUES
(@ID,
@code,
'AUTOGENERATE2',
'',
1,
1,
1,
1,
0,
1,
0,
1,
1,
0,
0,
1,
2,
1,
100,
100,
0,
0,
0,
0,
0,
0,
1,
'',
'',
'',
'8/29/2007 11:31:25 AM',
'',
'')
select @ID
Update Hosp_Counter set Counter_ID = @ID
where Table_Description = 'Medicines'
commit transaction

any help is very much appreciated!

'confused'
Joel

View 3 Replies


ADVERTISEMENT

Auto Generating An Email

Jun 5, 2006

Hi All,
I need to opening up a browser page everyday at 6am. (What I am trying to do is to send an email with some formatted output everyday at 6am)
Is there anyway to achive this via SQL 05 Express?
Thanks,
Mal.

View 4 Replies View Related

Auto Generating Numeric Column

Sep 5, 2006

Hi There,I want to create a column that usto numbers upto a specified value, and the resets. I've tried using the identity column and then using DBCC CHECKIDENT, but this doesnt doesn't have the desired affect. Here's an example of what I'm after.AutoRow1234 -------- reset1234 --------resetAny help would be great, many thanksStuart   

View 5 Replies View Related

Auto Generating Stored Procedures ?

Jan 17, 2007

Hi!
Let's say users of my app can build some reports based on a current database schema and my custom-database adapter will generate some SQL to get the right data. User can save his report template ( basically data needed to create SQL ) in some storage. Will it be better solution to generate stored procedure for such report and save stored proc to a database and their name with raport data so next time user needs this report it will use stored proc.
Jarod

View 1 Replies View Related

Generating Auto Incrementing No Using SQL Query

Sep 22, 2004

Hi everyone,

I am having a table with which i generate a report. Now how to using a SQL query i can generate a auto incrementing no.

Say i am executing this query

SELECT NAME,AGE,ADDRESS FROM MEMBER which gives

NAME AGE ADDRESS
HOLYMAC 13 MALACCA
HOLYCOW 25 USA
HOLYGOD 55 LONDON


Now how can i make it come out like this

SNO NAME AGE ADDRESS
1HOLYMAC 13 MALACCA
2HOLYCOW 25 USA
3HOLYGOD 55 LONDON

See the first column is a auto incrementing number 1,2,3.


How can I write a SQL QUERY that outputs a auto incrementing number.


Thank you
Have nice day

View 2 Replies View Related

Generating Auto Sequential Numbers

Jul 23, 2005

I am using sybase aSE12.5. I have a table with only one column withdatatype char(2). when i query this table to select all the records, ishould get these records in the ascending order and they should be numbered, i.e, the o/p should look something like thiscolumn_name------ --------1 AB2 AC3 ADand so on.I cannot add an extra column and i need this to be done in a single query.--Message posted via http://www.sqlmonster.com

View 2 Replies View Related

Auto-generating A DateTime In SQL Server Express 2005

Jul 22, 2007

Is it possible to have a DateTime field in a row automatically generated when a row is created?
ie:

INSERT INTO [TableName] ([DateTimeStamp], [UserId], [Title], [Explanation]) VALUES (DateTime.Now(), @UserId, @Title, @Explanation)
or something like that?

View 2 Replies View Related

SQL Code To Display Item

Jun 5, 2007

Is there any SQL code which displays one item if there is mutiple entry of same item. For example: in one columan I have many entry of one item, but I want to display only one item and also I want to display other column as well connecting with that item number.

View 10 Replies View Related

Generating Wrapper Code For SQL Server Stored Procedure

Dec 16, 2004

Hi

How Can I Generating wrapper code for SQL Server Stored Procedure ??

If You will Go To The Following link you will see an example for Generating wrapper code for Oracle Database .. And Also the author say there is built in tool for Generating wrapper code for SQL Server
http://www.codeproject.com/vb/net/OracleSPWrapper.asp
my question .. where is this tools ???

and thanks with my regarding

Fraas

View 1 Replies View Related

Getting The Foreground,Background Colors In The Report Item Dynamically Using Custom Code

Oct 25, 2007



Hi All,
I want to get the Font,Background colors of the report item(Textbox) changed in Runtime,According to the value in the Textbox. The idea is to get this done by using the Same Custom code for getting both the Foreground,Background colors, I thought to implement this with flag, But I dont know how to do this..

Reporting experts ..please help me with this issue.Thanks in Advance

-Mahendra

View 2 Replies View Related

Auto Code - Help

Feb 27, 2007

Hello all (:

I'm making a program, when I put the auto code script to generate code for clients, citys I receive this error:

Dynamic SQL Error
SQL Error code: -206
Column unknown CODCLIENTE
At line 1, column 12
-----------------------------

I was make a auto code for the city table, the script in the SQL statement is: select max (codcidade) as MAIOR from cidade...it's all OK

But when I do with client table I received the error above.
The script is completely right, the table name is right, column name too, but I don't know what is happening ;/

please someone help me and sorry, I don't speak english very well =P

View 4 Replies View Related

Auto Generate Code For Sp Parameters?

Apr 18, 2007

Is there an easy way to generate the parameters code for calling stored procedures?



Is there an easy way to generate stored procedure code without having to manually type it in? I've seen 3rd party tools, but I was wondering if there's anything within Sql Server to do it.



I'm using c#, visual studio 2005, sql server 2005.



Thanks,



John

View 3 Replies View Related

How To Code On Database To Send Auto Mail?

Sep 2, 2007

I want the server to send some auto email according to a column "expiry_date" in some table. How shall I do that? Use trigger?
Is it possible?

View 1 Replies View Related

Alpha Numeric Auto Increment Code In Sql Server 2000

Jan 25, 2006

Karikalan writes "We need alpha numeric auto increment code in sql server 2000.
(for eg.: ico1001, ico1002, ico1003,......)
Can any one send the code in MS sql server 2000? plz ..................
bcoz i am beginner in sqlserver 2000"

View 1 Replies View Related

Create A Query Where Semi Item Materials Are Also Listed In Finished Item Recipe?

Dec 6, 2013

I have a BOM table with all finished item receipes and semi items recipes. create a query where semi item materials are also listed in finished item recipe.

View 5 Replies View Related

Help, Running A Control Flow Item Does Not Kick Off The Next Item

Mar 6, 2007

Hi,

Here's my problem. I have 2 tasks defined in my Control Flow tab:

EXECUTE SQL--------->EXECUTE DTS 2000 PACKAGE

When I attempt to run it, by right-clicking the EXECUTE SQL task, and selecting "Execute Task", it only runs the EXECUTE SQL part (successfully), and does not "kick off" the EXECUTE DTS 2000 PACKAGE, after it is done running (even though it completes successfully, as shown by the green box).

Yes, they are connected by a dark green arrow, as indicated in my diagram above.

Why is this?? Am I missing something here? Need help.

THANKS

View 3 Replies View Related

How To Select The Last Identical Item# Until A Different Item# In The Table

Jul 12, 2007

Hello,Basically, I have a table with 2 fieldsId     item#1      33332      33333      22224      22225      22226      33337      33338      3333I would like to only select the last identical Item# which in this case would be  the id 6,7 and 8Any idea how could I do that?Thanks

View 1 Replies View Related

How Can I Create A New Custom Report Item? The Report Item Is Extends Matrix.

Jan 18, 2007

hi everyone

what the matrix's class name ?

where is the matrix's dll?

Can i create a new class extends the matrix?

I want to override the matrix's onpaint method.

Can i do this ?

why the table not have the column group?













View 9 Replies View Related

SQL 2012 :: SSMS Auto-recovery / Auto-save New (unsaved) Queries

Feb 16, 2014

Since upgrading from SQL Server Management Studio 2008 R2, I've noticed that it no longer autosaves queries that have not been manually saved first. If a file has been manually saved the autorecover files end up in the following directory:

%appdata%MicrosoftSQL Server Management Studio11.0AutoRecoverDatSolution1

However, I have ended up in the situation where I have unsaved queries when my computer has crashed and have not been able to recover them.

I have also found references to .sql files stored in temp files in the following directory, but the files here seem to be very haphazardly caught:

%userprofile%AppDataLocalTemp

View 2 Replies View Related

Finding Orders That Have At Least 1 Promo Item And 1 Non-promo Item

Oct 16, 2014

I am having trouble finishing the last bit of a report. The report shows orders that customers have placed that contain 0 promo items, All promo items (all items in order are promo items), and a mix of promo and non promo (at least 1 promo item and 1 non-promo item). Ive simplified this a bit for ease of understanding but lets assume we have 2 tables: A Promo table that contains the items on promotion and the dates that promotion is valid, and a Sales table, that contains the order number, order date, and sku ordered.

I've already written code that finds orders that have at least 1 promo item in them, and using that, I can determine what orders have 0 promo items in them. Where I am stuck is taking the orders that have at least 1 promo item in them, and separating them into orders that have only promo items, and those that have both promo and not promo items in them. Also, there are several promos throughout the year (called "Offers") so in my code below, you can see 2 different Offers ("JF" and "MA") with their corresponding dates they are valid. They will never overlap. My results also have to be split out by Offer so management can look at the results of each offer separately. Here is some code:

Code:
create table #Promos (
Offer varchar(2) null,
SKU int null,
StartDt date null,
EndDt date null

[Code] ....

So my results should show OrderNo A1111 in the Promo and No Promo group because of SKU 5 not being promotional during the time that order was placed. OrderNo A2222 should be in the Promo Only group because both SKUs on the order were promotional at the time the order was placed.

View 6 Replies View Related

Auto Increment Auto Non-identity Field

Jan 23, 2004

I have an MS SQL Server table with a Job Number field I need this field to start at a certain number then auto increment from there. Is there a way to do this programatically or within MSDE?

Thanks, Justin.

View 3 Replies View Related

Help With Converting Code: VB Code In SQL Server 2000-&&>Visual Studio BI 2005

Jul 27, 2006

Hi all--I'm trying to convert a function which I inherited from a SQL Server 2000 DTS package to something usable in an SSIS package in SQL Server 2005. Given the original code here:
Function Main()
on error resume next
dim cn, i, rs, sSQL
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=sqloledb;Server=<server_name>;Database=<db_name>;User ID=<sysadmin_user>;Password=<password>"
set rs = CreateObject("ADODB.Recordset")
set rs = DTSGlobalVariables("SQLstring").value

for i = 1 to rs.RecordCount
sSQL = rs.Fields(0).value
cn.Execute sSQL, , 128 'adExecuteNoRecords option for faster execution
rs.MoveNext
Next

Main = DTSTaskExecResult_Success

End Function

This code was originally programmed in the SQL Server ActiveX Task type in a DTS package designed to take an open-ended number of SQL statements generated by another task as input, then execute each SQL statement sequentially. Upon this code's success, move on to the next step. (Of course, there was no additional documentation with this code. :-)

Based on other postings, I attempted to push this code into a Visual Studio BI 2005 Script Task with the following change:

public Sub Main()

...

Dts.TaskResult = Dts.Results.Success

End Class

I get the following error when I attempt to compile this:

Error 30209: Option Strict On requires all variable declarations to have an 'As' clause.

I am new to Visual Basic, so I'm on a learning curve here. From what I know of this script:
- The variables here violate the new Option Strict On requirement in VS 2005 to declare what type of object your variable is supposed to use.

- I need to explicitly declare each object, unless I turn off the Option Strict On (which didn't seem recommended, based on what I read).

Given this statement:

dim cn, i, rs, sSQL

I'm looking at "i" as type Integer; rs and sSQL are open-ended arrays, but can't quite figure out how to read the code here:

Set cn = CreateObject("ADODB.Connection")

cn.Open "Provider=sqloledb;Server=<server_name>;Database=<db_name>;User ID=<sysadmin_user>;Password=<password>"

set rs = CreateObject("ADODB.Recordset")

This code seems to create an instance of a COM component, then pass provider information and create the recordset being passed in by the previous task, but am not sure whether this syntax is correct for VS 2005 or what data type declaration to make here. Any ideas/help on how to rewrite this code would be greatly appreciated!

View 7 Replies View Related

How To Show Description In Report Instead Of Code (Desc For Code Is In Master Table)

Mar 28, 2007

Dear Friends,



I am having 2 Tables.

Table 1: AddressBook
Fields --> User Name, Address, CountryCode



Table 2: Country
Fields --> Country Code, Country Name


Step 1 : I have created a Cube with these two tables using SSAS.



Step 2 : I have created a report in SSRS showing Address list.

The Column in the report are User Name, Address, Country Name



But I have no idea, how to convert this Country Code to Country name.

I am generating the report using the Layout tab. ( Data | Layout | Preview ) Report1.rdl [Design]



Anyone help me to solve this issue. Because, in our project most of the transaction tables have Code and Code description in master table. I need to convert all code into corresponding description in all my reports.




Thanks in advance.





Regards
Ramakrishnan
Singapore
28 March 2007

View 4 Replies View Related

Item

Jan 12, 2005

I want read
dr[2] = SqlDataReader dr1.item("lastmane");
from database
but I have error expected
I don't while


SqlDataReader dr1 = cmd.ExecuteReader();
dr1.Read();

dr[2] = SqlDataReader dr1.item("lastmane");

View 2 Replies View Related

Need Sum Of A Particular Item

Apr 23, 2008

select i.a,
w.c,
w.e
from table1 i,table2 w where
i.a=w.a (Here c is the primary key for each a)-iam getting o/p like this

a c e

aaa x 2
aaa y 10
bbb y 5
ccc x 3
ccc y 4

i need o/p in this way (ie sum of e for each a)
a e
aaa 12
bbb 5
ccc 7

Is it possible

Thanx

View 1 Replies View Related

Get Item Name Instead Of ID

Jan 11, 2014

I´m trying to get a query where I´ll get an answer like this:

+--------------+----------------+----------------+------------------+-----------------+
| champion_id | champion_name | champion_item1 | champion_item... | champion_item16 |
+--------------+----------------+----------------+------------------+-----------------+
| 1 | Legolas | boots | ... | sword |
+--------------+----------------+----------------+------------------+-----------------+

This is the scenario how I set up my tables (let me know if I should change it):

table champions

+--------------+----------------+
|champion_id | champion_name |
+--------------+----------------+
| 1 | Legolas |
+--------------+----------------+

table equipment

+--------------+----------------+------------------+-----------------+
| champion_id | champion_item1 | champion_item... | champion_item16 |
+--------------+----------------+------------------+-----------------+
| 1 | 5 | ... | 22 |
+--------------+----------------+------------------+-----------------+

table items

+--------------+----------------+
| item_id | item_name |
+--------------+----------------+
| 5 | boots |
+--------------+----------------+
| 22 | sword |
+--------------+----------------+

But I still don´t know how to call the equipment table and get champion name and item names for the numbers. What did I do wrong and how can I fix it?

The foreign keys are in place.

View 5 Replies View Related

Many Lines Of Code In Stored Procedure && Code Behind

Feb 24, 2008

Hello,
I'm using ASP.Net to update a table which include a lot of fields may be around 30 fields, I used stored procedure to update these fields. Unfortunatily I had to use a FormView to handle some TextBoxes and RadioButtonLists which are about 30 web controls.
I 've built and tested my stored procedure, and it worked successfully thru the SQL Builder.The problem I faced that I have to define the variable in the stored procedure and define it again the code behind againALTER PROCEDURE dbo.UpdateItems
(
@eName nvarchar, @ePRN nvarchar, @cID nvarchar, @eCC nvarchar,@sDate nvarchar,@eLOC nvarchar, @eTEL nvarchar, @ePhone nvarchar,
@eMobile nvarchar, @q1 bit, @inMDDmn nvarchar, @inMDDyr nvarchar, @inMDDRetIns nvarchar,
@outMDDmn nvarchar, @outMDDyr nvarchar, @outMDDRetIns nvarchar, @insNo nvarchar,@q2 bit, @qper2 nvarchar, @qplc2 nvarchar, @q3 bit, @qper3 nvarchar, @qplc3 nvarchar,
@q4 bit, @qper4 nvarchar, @pic1 nvarchar, @pic2 nvarchar, @pic3 nvarchar, @esigdt nvarchar, @CCHName nvarchar, @CCHTitle nvarchar, @CCHsigdt nvarchar, @username nvarchar,
@levent nvarchar, @eventdate nvarchar, @eventtime nvarchar
)
AS
UPDATE iTrnsSET eName = @eName, cID = @cID, eCC = @eCC, sDate = @sDate, eLOC = @eLOC, eTel = @eTEL, ePhone = @ePhone, eMobile = @eMobile,
q1 = @q1, inMDDmn = @inMDDmn, inMDDyr = @inMDDyr, inMDDRetIns = @inMDDRetIns, outMDDmn = @outMDDmn,
outMDDyr = @outMDDyr, outMDDRetIns = @outMDDRetIns, insNo = @insNo, q2 = @q2, qper2 = @qper2, qplc2 = @qplc2, q3 = @q3, qper3 = @qper3,
qplc3 = @qplc3, q4 = @q4, qper4 = @qper4, pic1 = @pic1, pic2 = @pic2, pic3 = @pic3, esigdt = @esigdt, CCHName = @CCHName,
CCHTitle = @CCHTitle, CCHsigdt = @CCHsigdt, username = @username, levent = @levent, eventdate = @eventdate, eventtime = @eventtime
WHERE (ePRN = @ePRN)
and the code behind which i have to write will be something like thiscmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@eName", ((TextBox)FormView1.FindControl("TextBox1")).Text);cmd.Parameters.AddWithValue("@ePRN", ((TextBox)FormView1.FindControl("TextBox2")).Text);
cmd.Parameters.AddWithValue("@cID", ((TextBox)FormView1.FindControl("TextBox3")).Text);cmd.Parameters.AddWithValue("@eCC", ((TextBox)FormView1.FindControl("TextBox4")).Text);
((TextBox)FormView1.FindControl("TextBox7")).Text = ((TextBox)FormView1.FindControl("TextBox7")).Text + ((TextBox)FormView1.FindControl("TextBox6")).Text + ((TextBox)FormView1.FindControl("TextBox5")).Text;cmd.Parameters.AddWithValue("@sDate", ((TextBox)FormView1.FindControl("TextBox7")).Text);
cmd.Parameters.AddWithValue("@eLOC", ((TextBox)FormView1.FindControl("TextBox8")).Text);cmd.Parameters.AddWithValue("@eTel", ((TextBox)FormView1.FindControl("TextBox9")).Text);
cmd.Parameters.AddWithValue("@ePhone", ((TextBox)FormView1.FindControl("TextBox10")).Text);
cmd.Parameters.AddWithValue("@eMobile", ((TextBox)FormView1.FindControl("TextBox11")).Text);
So is there any way to do it better than this way ??
Thank you

View 2 Replies View Related

Custom Code (Embedded Code) Question

Oct 16, 2007



Hi all,

Could someone tell me if custom code function can capture the event caused by a user? For example, onclick event on the rendered report?

Also, can custom code function alter the parameters of the report, or refresh the report?

Thanks.

View 2 Replies View Related

How To Get The Last Item Added

Dec 14, 2004

Not 100% sure how to do this so I would appreciate some directions. I have 2 tables, Systems and Contacts. A system can have 1 to infinite contacts and contact can have 1 to infinite systems. So I use a 3rd table Sys_Con to add the contact needed for each system.
Now my question is once I add the System and contact how do I know for sure which ContactID to add in my Sys_Con table? Because while I am doing this operation maybe someone can add an other contact. So is there a way for my store proc Add_Contact to return the contactID needed for my store proc Add_Sys_Con ?

TABLE Sys_Con
SystemID int
ContactID int

Table Contact
ContactID int Identity
ContactName
...

Table System
SystemID
...

View 3 Replies View Related

Get Only ONE Row Per Item With Different Fields

Nov 25, 2007

Hi,

I'm a bit stuck here.
I have a table called STM_COMM and it contains following fields: id, member_id, email_addr, tel_nr, fax_nr

A member can have multiple email addresses, telephone numbers and faxnumbers. so we could have something like this:

id member_id email_addr tel_nr fax_nr
-------------------------------------------------------
1 5 info@test.com
2 5 555687 568774
3 66 test@go.nl 65897854
4 5 another@one.com

What I would like to have is only ONE (1) row PER member with only the FIRST (not max!) entered known data. In the above case, I'd like to have this as result:

member_id email_addr tel_nr fax_nr
----------------------------------------------------
5 info@test.com 555687 568774
66 test@go.nl 65897854

I've tried lots of things (max, inner select ...) but I can't seem to figure it out.

Thank you for the help !

Christophe

PS: I'm working on a sql server 2005

View 1 Replies View Related

Get Value Of Last Item In Column?

Mar 7, 2007

How can I get the value of the last Item in a coums?SELECT COLUMN FROM DATABASE ORDER BY COLUMN DESC?something with Fields(0).value?Thank you in advance

View 4 Replies View Related

No Item Showed

Feb 27, 2007

Hi gurus

I have sql server 2000 that was working fine until today(figures), today I opened EM and under sql server group where used to be all my information now there is NO ITEM, nothing shows(database,Nothing) The server is working as I had no complaints from my user on data not been saved or getting data from but its strange that I can not see all my info like I used to.- If I go into sql query analizer, it ask me to connect to local which I do and I can see all my databases from there but once I close that window ,on my EM nothing shows.

I checked all services andevery one of them seems to be up and runnig

Thanks forall the help I can get

View 4 Replies View Related

How To Get The Max Value Of Duplicate Item

Aug 8, 2007



Hi Every Body,
I have one table it's called -Access.It contains two columns name of that is Door,Emp_Id.
example Door Emp_Id
10 1
10 2
10 3
11 4
12 5
11 1
this is the value in that table.......
I want get Which Door number maximum Access from the table.....
Thanks & Regards,
S.Sajan

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved