|
my table have columns p1,p2,..p30,
in stored procedure using cursor this values are fetched in @p1, @p2..,@p30
|
|
|
|
|
Your table has columns that look like this? What on earth do they store? How can you tell that you've normalised the table?
I'm sorry, but how maintainable is this system going to be? Where do I put a value - is it in column P6 or is it in column P16. There is no cue to help me decide - and hence, there will likely be no standard.
Plus, why does your table have 30 columns? Have you denormalised it?
Please - take this opportunity to sort out the table. You will find that it pays dividends in the long run.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
From reading your other responses, I'm assuming you did NOT mean to capitilize P5 the one time...
This is basically just a table lookup problem--except that instead of storing the values in the database, you are storing them in programming variables. The basic idea is roughly the same, except that YOU get to write the lookup routine instead of letting the DB do it for you.
There are three basic approaches. In each example, I'll assume you have already retrieved the database value of @v into a local variable of the same name.
First, a simple linear scan of each variable name:
switch( @v )
{
case '@p1' : @p1
case '@p2' : @p2
case '@p3' : @p3
...
case '@p30' : @p30
default NULL
}
Second, ahead of time, put all the values into an associative array (essentially two arrays; one which contains the indices (names), and one which contains the values).
void initialize()
{ p_val(1)= @p1; p_val(2)= @p2; ...
p_ndx(1)='@p1'; p_ndx(2)='@p2' ...
}
then do a scan on the indices to find the value:
variant get_p_value( string p_name )
{ int curr_ndx = 1;
while( p_ndx( curr_ndx ) <> p_name ) curr_ndx++;
return p_val( curr_ndx );
}
A better approach would be to sort the values on p_ndx, and do a binary search instead of linear scan.
Third, if you don't know ahead of time all the possible names '@pX', you will have to use a language that has runtime evaluation ability, like Perl, or even VB.
return_value = eval( @v );
Of course one of the reasons we normally use database managements systems is to avoid all this nonsense.
SELECT val FROM myTable WHERE name=@v;
Hope this helps.
-- modified at 9:43 Friday 20th July, 2007
|
|
|
|
|
how can i use sequence number in insert comand so any time i click insert button a sequence number will fill up the id column
i am using vb.net and oracle
lets say i have a table with 2 colomn,
id integer
name string
what will be the insert comand?
please help. thanks
|
|
|
|
|
mindgameny wrote: a sequence number will fill up the id column
Are you looking for identity columns ? That will generate unique values for the column on each inserts
|
|
|
|
|
Oracle doesn't use an identity column.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Oops . I didn't notice it was for oracle.,
|
|
|
|
|
No problem. I was halfway through typing a response about using scope_identity when I noticed that. Perhaps he needs to learn that it's Oracle with a capital O. Much more noticable that way.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
One way of doing this in Oracle (and I believe it's probably the easiest) is to use a trigger. Suppose that you have the following table:
create table myTable
(
id number(10),
name varchar2(20);
)
alter table myTable
add (constraint mytable_pk primary key (id)); Create a sequence for this:
create sequence myTable_seq; Now, you write a pre-insert trigger:
create or replace trigger myTable_Insert
before insert on myTable
for each row
when (new.id is null)
begin
select myTable_seq.NEXTVAL
into :new.id
from dual;
end; To test this, enter:
INSERT INTO myTable(name) values ('Test');
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks a lot for your help
it helps me a lot for my project and i was able to do it in sql
but now i want to write code on vb.net for same purpose.
is that posible?
the data table is already in database (oracle)
and i cant change it.
so where and what i need to do in vb.net. please help
thanks a lot
|
|
|
|
|
Just because the table is in place doesn't mean that you can't use this technique. All you need to do is create the sequence table and the pre-insert trigger. They won't affect your table in the slightest.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
We often need quick access to our sql data. Often we open SQL Analyzer to grab the data when we know exactly what we want. Other non-SQL users wade through the application housing the data.
I just thought of creating a web application where users could "crawl" the data by choosing their database and table and being presented with the data. Then they could drill down in the data by clicking links that are based on the table's foreign keys.
In a perfect world there would be many features such as
* Having custom converters based on the data such as showing text values rather than foreign key ids that link to a lookup table, showing numbers in specified formats, displaying a picture rather than the path, etc.
* Allowing security based on passed credentials or a user entered username/password. Passed credentials would allow access to the data the user has initial rights to. Manual user credentials would be useful for giving access to specific areas not available to the user or testing access to user accounts that applications use.
* Searching
* ???
Before I go and create something like this (which would be fun) does anyone know of something similar? An application with the source code available would be preferable but I'd be willing to take a look at closed commercial apps as well.
Thanks!
Matt Penner
|
|
|
|
|
|
Sorry, not quite sure what you mean by that reply. A little more specific?
I'm not much of a fan of Access. I don't see how it would help me accomplish what I'm trying to do.
Thanks.
|
|
|
|
|
MS Access can link to a SQL Server database and then your users can use the query builder to get to the data. Means that there's no direct link into sql server (if you connect with a read only user) and they will be using an interface that many of them are probably already used to.
|
|
|
|
|
how pictures are stored in a table column
|
|
|
|
|
mavii wrote: how pictures are stored in a table column
put them in a varbinary(max) column.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Is there any way to change the date format in sql server 2005 forever?? I mean, in a way that all connection use this format.
The instruction set dateformat works fine, but I need that all connections start with a certain date format. I can't change the format before the program connects to the database.
Thanks
Peterson
|
|
|
|
|
Peterson Luiz wrote: Is there any way to change the date format in sql server 2005 forever?? I mean, in a way that all connection use this format.
There is no format. It is an illusion. SQL Server does not store dates in any specific format. It may interpret SQL statements as having a certain format, but generally good practice is to use ISO format (yyyy-mm-dd) so there is no ambiguity. Where possible you should be using paramerised queries so that when you pass a date to the database you pass a DateTime object from .NET - which means you no longer have to worry about the date format.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
But in my case, I have an old C++ program that stores the dates in the format mm/dd/yy hh:mm:ss.
If I do a set dateformat mdy, I can do an insert with the mm/dd/yy format. The default of my sql server for some reason is dmy.
When I try to insert the data whitout setting the dateformat to mdy I get I conversion error.
Thanks
Peterson
|
|
|
|
|
Most C++ database frameworks have facilities to pass parameters.
And, just to reiterate, it is generally good practice to use ISO date format rather than a regional variant format. It is the job of the presentation layer of your application to format and interpret dates, not the database.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
DATEFORMAT inherits its setting from the server's default language. You can set this in various ways, see Books Online for details (look for 'default language Option' in the index).
Your database connection method may have a way to specify a different language. Both the ODBC driver and OLE DB provider accept a Language option which can be used to override the default.
|
|
|
|
|
hi i have big problem with my replication
i created replication on maaster server (Sql server enterprise) replication name Client3G (transaction) then i create subscriptions on other sql server instance( developer ) by Client3G
but when run it make error . this error ('the process could not connect to distributo 'data'. the step failed')
123
|
|
|
|
|
if i want to display only last entered 4 records from a table, then which query will be written
|
|
|
|
|
mavii wrote: if i want to display only last entered 4 records from a table, then which query will be written
Well, The table needs a date stamp (DateTime column) that records when data was inserted.
SELECT TOP 4 * FROM MyTable<br />
ORDER BY DateStamp DESC
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|