Showing posts with label third. Show all posts
Showing posts with label third. Show all posts

Friday, March 23, 2012

I want to find first,second,third,fourth highest from a column of a table

I have tried using max ,Group By and TOP for finding
first,second,third,fourth highest from a column of a table
PLs help me
Thanks in AdvanceHi
create table abhi (
col1 char(1),
col2 int
)
insert into abhi values('A',10)
insert into abhi values('A',8)
insert into abhi values('A',7)
insert into abhi values('A',5)
insert into abhi values('A',4)
insert into abhi values('B',12)
insert into abhi values('B',8)
insert into abhi values('B',6)
insert into abhi values('B',4)
insert into abhi values('B',5)
insert into abhi values('B',3)
DECLARE @.myrow INT
SET @.myrow=2 --change it for your needs
SELECT * FROM abhi a
WHERE (
SELECT COUNT(*) FROM abhi
WHERE col1 = a.col1
AND col2 > a.col2
) <@.myrow
ORDER BY col1, col2 DESC
"ABHI" <abhijitbavdhankar@.gmail.com> wrote in message
news:1129807557.453049.121480@.g14g2000cwa.googlegroups.com...
>I have tried using max ,Group By and TOP for finding
> first,second,third,fourth highest from a column of a table
> PLs help me
> Thanks in Advance
>sql

Wednesday, March 21, 2012

I want to find first,second,third,fourth highest from a column of a table

I have tried using max ,Group By and TOP for finding
first,second,third,fourth highest from a column of a table
PLs help me
Thanks in Advance
Hi
create table abhi (
col1 char(1),
col2 int
)
insert into abhi values('A',10)
insert into abhi values('A',8)
insert into abhi values('A',7)
insert into abhi values('A',5)
insert into abhi values('A',4)
insert into abhi values('B',12)
insert into abhi values('B',8)
insert into abhi values('B',6)
insert into abhi values('B',4)
insert into abhi values('B',5)
insert into abhi values('B',3)
DECLARE @.myrow INT
SET @.myrow=2 --change it for your needs
SELECT * FROM abhi a
WHERE (
SELECT COUNT(*) FROM abhi
WHERE col1 = a.col1
AND col2 > a.col2
) <@.myrow
ORDER BY col1, col2 DESC
"ABHI" <abhijitbavdhankar@.gmail.com> wrote in message
news:1129807557.453049.121480@.g14g2000cwa.googlegr oups.com...
>I have tried using max ,Group By and TOP for finding
> first,second,third,fourth highest from a column of a table
> PLs help me
> Thanks in Advance
>

I want to find first,second,third,fourth highest from a column of a table

I have tried using max ,Group By and TOP for finding
first,second,third,fourth highest from a column of a table
PLs help me
Thanks in AdvanceHi
create table abhi (
col1 char(1),
col2 int
)
insert into abhi values('A',10)
insert into abhi values('A',8)
insert into abhi values('A',7)
insert into abhi values('A',5)
insert into abhi values('A',4)
insert into abhi values('B',12)
insert into abhi values('B',8)
insert into abhi values('B',6)
insert into abhi values('B',4)
insert into abhi values('B',5)
insert into abhi values('B',3)
DECLARE @.myrow INT
SET @.myrow=2 --change it for your needs
SELECT * FROM abhi a
WHERE (
SELECT COUNT(*) FROM abhi
WHERE col1 = a.col1
AND col2 > a.col2
) <@.myrow
ORDER BY col1, col2 DESC
"ABHI" <abhijitbavdhankar@.gmail.com> wrote in message
news:1129807557.453049.121480@.g14g2000cwa.googlegroups.com...
>I have tried using max ,Group By and TOP for finding
> first,second,third,fourth highest from a column of a table
> PLs help me
> Thanks in Advance
>

Monday, March 19, 2012

I want to add two text columns

Hi all,
I have a two text columns in my table with more than 100,000 rows.
I want to create a third text column with the data from text column 1 + text
column 2.
Is there an easy way to concatinate two text fields?
Thanks
RajuNo, there is no easy way. Why would you want to do this? Is your SQL
statement too long when you list both columns? This seems like a weird
requirement to me. Usually you use separate TEXT columns because you need
them separate. Otherwise, most applications could have just used a single
text column in the first place.
If you have less than 8000 characters in each column, you could use a view,
and say:
SELECT
..,
ConcatenatedColumn = CONVERT(VARCHAR(8000), textCol1)
+ CONVERT(VARCHAR(8000), textCol2)
FROM
..
Then, you don't have to change the underlying table, or any of the
procedures / apps that insert/update the data. (Or, better yet, if you
don't need TEXT, change the columns to VARCHAR.)
Otherwise, the best way would probably be to add the 3rd column, use an
external app to loop through, concatenate, and update the new column, and
then delete the first two columns. (An external app will be much more
friendly with joining the two values than SQL Server will be internally.)
A
"Raju" <npraju1@.hotmail.com> wrote in message
news:%23mM%237ZCAGHA.2040@.TK2MSFTNGP14.phx.gbl...
> Hi all,
> I have a two text columns in my table with more than 100,000 rows.
> I want to create a third text column with the data from text column 1 +
> text
> column 2.
> Is there an easy way to concatinate two text fields?
> Thanks
> Raju
>|||Aaron,
Thank you for your response.
Actually we have legacy application, which has summary in one text column
and description in one text column.
Our new application has only one column, now my job is to get those two
columns into one new column in our new application.
Hope this helps.
BTW
Unfortunately I can't use your solution as both the columns have huge data,
more than 8000 bytes.
Thanks
Raju
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eWjN6eCAGHA.1256@.TK2MSFTNGP15.phx.gbl...
> No, there is no easy way. Why would you want to do this? Is your SQL
> statement too long when you list both columns? This seems like a weird
> requirement to me. Usually you use separate TEXT columns because you need
> them separate. Otherwise, most applications could have just used a single
> text column in the first place.
> If you have less than 8000 characters in each column, you could use a
view,
> and say:
> SELECT
> ...,
> ConcatenatedColumn = CONVERT(VARCHAR(8000), textCol1)
> + CONVERT(VARCHAR(8000), textCol2)
> FROM
> ...
> Then, you don't have to change the underlying table, or any of the
> procedures / apps that insert/update the data. (Or, better yet, if you
> don't need TEXT, change the columns to VARCHAR.)
> Otherwise, the best way would probably be to add the 3rd column, use an
> external app to loop through, concatenate, and update the new column, and
> then delete the first two columns. (An external app will be much more
> friendly with joining the two values than SQL Server will be internally.)
> A
>
> "Raju" <npraju1@.hotmail.com> wrote in message
> news:%23mM%237ZCAGHA.2040@.TK2MSFTNGP14.phx.gbl...
>