|
|
techs = network admins, you know hamster trainers!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Friend!
i've faced a problem.
Suppose, i have 10 records in a table.i want only the 2nd 0r 3rd position record. how can i achieve it?
thanks.......
|
|
|
|
|
This is a quick and dirty script I knocked up to illustrate one method of pulling out the second and third record.
There are more elegant solutions.
select top 1 itemnumber into #a from stocktable
order by itemnumber
select top 3 itemnumber into #b from stocktable
order by itemnumber
select #b.itemnumber from #b
left join #a
on #b.itemnumber = #a.itemnumber
where #a.itemnumber is null
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
More 1 votes please
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Create Table #r
(
id --Identity column. Use your SQL databas's syntax here.
--For example, SQL Server is Identity(1,1).
...--Columns in the table
)
Insert #r(...--Columns in table)
Select *
From YourTable
Order By YourColumn
Select *
From #r
Where id in (2,3)
What that does is creates a new table with the same build of YourTable with an added identity column. It inserts the records and orders it, an important step is to order it or you'll may get different rows each time you run. Change the 2,3 in the in statement to get any row number you want.
|
|
|
|
|
Well ... if you are using SQL 2005 ... I think this is what you are looking for
CREATE TABLE #T (id INT IDENTITY(1,1), aField NVARCHAR(10) ) ;
INSERT INTO #T (aField) SELECT 'one' ;
INSERT INTO #T (aField) SELECT 'two' ;
INSERT INTO #T (aField) SELECT 'three' ;
INSERT INTO #T (aField) SELECT 'four' ;
INSERT INTO #T (aField) SELECT 'five' ;
INSERT INTO #T (aField) SELECT 'six' ;
INSERT INTO #T (aField) SELECT 'seven' ;
SELECT * FROM #T ORDER BY aField DESC
;WITH myTable AS (
SELECT
ROW_NUMBER() OVER( ORDER BY aField DESC ) AS RowNo
, id
, aField
FROM #T
)
SELECT *
FROM myTable
WHERE RowNo IN ( 2 , 4 ) ;
DROP TABLE #T ;
Please... SAVE my time by rating the posts that you read!
There are 10 kinds of people in the world: those who understand binary and those who don't.
modified on Friday, July 25, 2008 8:38 AM
|
|
|
|
|
This is what I would use in SQL 2000 :
CREATE TABLE #T (id INT IDENTITY(1,1), aField NVARCHAR(10) ) ;
INSERT INTO #T (aField) SELECT 'one' ;
INSERT INTO #T (aField) SELECT 'two' ;
INSERT INTO #T (aField) SELECT 'three' ;
INSERT INTO #T (aField) SELECT 'four' ;
INSERT INTO #T (aField) SELECT 'five' ;
INSERT INTO #T (aField) SELECT 'six' ;
INSERT INTO #T (aField) SELECT 'seven' ;
SELECT IDENTITY(INT, 1 , 1) AS RowNo, 0+id AS id, aField
INTO #Z
FROM #T
ORDER BY aField DESC
SELECT * FROM #Z
SELECT * FROM #Z WHERE RowNo IN ( 2 , 4 ) ;
DROP TABLE #T ;
DROP TABLE #Z ;
Please... SAVE my time by rating the posts that you read!
There are 10 kinds of people in the world: those who understand binary and those who don't.
|
|
|
|
|
If you really only have 20 or so records, why wouldn't you load all of the records into an array, then access the Nth element whenever you want. If this is lookup type data you could load this array once and save yourself lots of headaches with complex SQL. I'm a big fan of keeping things simple. Just a thought.
|
|
|
|
|
David Mujica wrote: If you really only have 20 or so records
If you have 20 records and you only need 1, why load other 19 records if you know that you'll throw them away anyway ?
What if you have 10000 users loading extra 19 records everytime ?
David Mujica wrote: save yourself lots of headaches with complex SQL
I cannot agree with this ... I prefer the headaches
Please... SAVE my time by rating the posts that you read!
There are 10 kinds of people in the world: those who understand binary and those who don't.
|
|
|
|
|
select top 2 rowposition from tablename where rowposition > 1
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
Regardless of all the fine answers you have been given, why do you need to read all the records if you know you need one of them?
What I mean is, if you know you want the nth record there must be something that makes it the one you want, so why not put that criteria in the original select?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Actually we have this requirement when calculating VAR, get the 500 scenarios, sort by your worst exposure and get 5th worst exposure of 500, rowposition does this.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Everybody,
I have Visual Studio 2005 and SQL Server 2005 installed on my PC which runs on Windows XP PE.The problem is when I finished the setup of SQL Srver 2005 it was not getting connected using SQL Server Authentication, so I used windows authentication.Now I developed an application it is running on my PC but whenever I am running it using IIS the connection can not be established with SQL Server.What can be wrong? how can i create a user with password on SQL Server? Also if i create this application fully fuctionable on my machine then at the time of deployment will it create any problem on the remote server?
One last point:Can anyone give me a sample connection string for remote server.I know it for my PC only but what parameters i have to give when connecting to a remote database and how?
|
|
|
|
|
if u have user id and pwd then use the following:
Data Source=urServerAddress;Initial Catalog=urDataBase;User Id=myUsername;Password=myPassword;
if u r using windows authentication then use the following:
Data Source=urServerAddress;Initial Catalog=urDataBase;Integrated Security=SSPI;
Abdul Sami,
Systems Analyst
|
|
|
|
|
Clickety[^]
You will need to change the connection types allowed to both integrated & sql standard.
Create an application specific standard identity in SQL server, give it adequate rights to your database (not sa and probably not DBO). We have a script that grants execute on all procs and select on all tables & views.
Use the standard creds in the connection string you decide to use!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I used CDaoDatabase and its sibling classes in my app, but I can not install the app in customers' computer.
I guess that some dlls or registers are missing, because all are fine if I install VC++ on customers PC.
If I change database calsses from CDaoDatabase to CDatabase, there is no installation problem, so I think all troubles are from dao's issues.
I am using Visual studio 6.0 on Windows XP platform.
I do like dao database because it is much more powerful, but I can not install my app for customers.
how do you install your dao app for customers?
thanks
|
|
|
|
|
|
I had never heard of CDaoDatabase, however this seem to indicate there are plenty of resources out there to research try.
clickety[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi guys,
I am pretty new to using MS Access data base and its connectivity.I have a webpage which is made up of HTML.This webpage has some fields in it.I have developed this webpage using Dreamweaver MX technology.
As soon as the users type the information and submit the values,I have designed the webpage to be in such a manner that the information is sent to my email.
Now I am trying to develop a way ,where the user values are stored in my MS Access database.Can anyone help me out in this regard.
What actually needs to be done.How can I establish the connectivity.I am pretty much confused as to what connection strings I should use.Should I change the HTML page to .aspx page????Kindly let me know in detail.Thanks a lot.
Regards,
Vamsee.
|
|
|
|
|
You are posting in the wrong Forum, you should have used ASP.NET Forum, but now to answer your question you have to write a data layer class that will interact with your page and create a Stored Procedure for insert. So that means when a user clicks Submit the data layer wil take the Parameters passed in your form and pass it in the Stored procedure and your records will be in the Database. like at this article and it can be done in Web too
http://www.codeproject.com/KB/cs/NTier.aspx[^]
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Sorry,
That I have posted in the wrong Place.Your explanation was very good.I will try this and get back to you if I have any doubts.Thanks a lot.
|
|
|
|
|
Your are welcome, am glad i helped.
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
hi vamseeraja,
why don´t you became pretty new using SQL Server database, and by the way, became also pretty new using aspx too, instead of html!!!
|
|
|
|
|
Ya I can do that...
But the client I work for are not Computer geeks.so my Boss who also works along with me wants it to be simple technology.So I thought that.Also she wants the database to be in MS Access.
Thanks a lot for suggesting me.
|
|
|
|