Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL question

Author  Topic 

Jorje123
Starting Member

2 Posts

Posted - 2011-03-28 : 09:38:59

I have a question.
I have a table "table1" that has and ID Integer and a VARCHAR(64).

Let's say i have this in "table1":

(1, 'Jorje is the Worst')
(2, 'one of the best')

How can i get 'Jorje is the best' from those 2 entries?

Thank you for all your help.
I am new to SQL.

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-03-28 : 09:43:13


Select top 1 'Jorje is the best' From table1


Really though, you will need to describe what kind of 'rule' you are trying to apply. otherwise... we can't help you.

Corey

snSQL on previous signature "...Oh and by the way Seventhnight, your signature is so wrong! On so many levels, morally, gramatically and there is a typo!"
Go to Top of Page

Jorje123
Starting Member

2 Posts

Posted - 2011-03-28 : 09:45:58
Hi Seventhnight,

Sorry for not being clearer.
I want to get 'Jorje is' from the 1st entry and 'the best' from the 2nd entry in the table. So that i can concat them and print on the screen 'Jorje is the best'.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-03-28 : 09:53:47
I'm not sure I see the practical application of this... but...


declare @table1 table (
id int,
string VARCHAR(64)
)

Insert Into @table1 values(1, 'Jorje is the Worst')
Insert Into @table1 values(2, 'one of the best')


Select
max(case id when 1 then SUBSTRING(string,1,8) else null end) +
max(case id when 2 then SUBSTRING(string,7,9) else null end)
From @table1


Corey

snSQL on previous signature "...Oh and by the way Seventhnight, your signature is so wrong! On so many levels, morally, gramatically and there is a typo!"
Go to Top of Page
   

- Advertisement -