how to select content in database? [closed] - sql-server

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I would like ask if this is possible in any database. Lets say there's one column on my database that has a content like this:
-----------------
|columname |
-----------------
| roan,joan,keith|
------------------
If I do a select query, can I just display roan from that field?
Thanks,

MSSQL version of Mark answer:
SELECT SUBSTRING(columnname, 1, CHARINDEX(',', columnname, 1) - 1) FROM testtable;

Oracle solution:
select substr(columnname,1,instr(columnname,',')-1) from testtable;

Related

SQL Server: display merge of records by user in one row with condition [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have the following table and need the following result with join based on username
Query
select
iif(count(*)>1, min(ID), max(right([User], 1))) ID,
[User],
iif(count(*)>1, concat('Total: (', cast(count(*) as varchar(12)), ')'), max(replace([Text], 'Text', 'Texto'))) [Text]
from
MyTable
group by
[User]
order by 1;
Results
ID User Text
1 User01 Total: (3)
2 User2 Texto 4
3 User3 Texto 5
6 User04 Total: (2)

How to give system date while creating SQL table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
SQL Server creating table error.
How to give system date, system date + 2 days while creating a table?
Is the system date the same as the current date?
You can try the SQL DEFAULT Constraint as shown below if I understood your question properly:
Create table Test(id int
, name varchar(20)
, dtDate datetime default DateAdd(dd, 2, getdate()))
insert into Test (id, name) values
(1, 'A')
select * from Test
Live db<>fiddle demo.

How can seprate string in three parts [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to Substring the string which is delimited
ABC/123/DEF
I want in
ABC in 1st column
123 in 2nd Column
DEF in 3rd Column
If your database in sql server you can try this:
declare #t table (name varchar(50))
insert into #t values ('ABC/123/DEF')
select PARSENAME(replace(name,'/','.'),3),PARSENAME(replace(name,'/','.'),2) , PARSENAME(replace(name,'/','.'),1) from #t

Pivot selected columns into rows with SQL Server [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a column-based table like this:
And I need to convert it to a row-based table like this:
Any help would be appreciated.
I think you need an UNPIVOT -
SELECT OrgID, Property, DataValue
FROM (SELECT OrgID, Property, DataValue
FROM YOUR_TABLE
UNPIVOT
(
DataValue FOR Property IN (ExtensionDigits
,StartExtension
,LastUsedExtension
,Server1IP
,Server2IP
,ServerPort
,IsFunctionOn
,VolumeDecibel)
) unpvt) temp
WHERE DataValue IS NOT NULL;

select with condition -Sql server [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a table test as the following
Contract date_prolog hours
-------------------------------
No 20
Yes 24/02/2014 10
No 30
No 10
How can I get this results ?
Contract date_prolog hours
-------------------------------
No 24/02/2014 20
No 24/02/2014 30
No 24/02/2014 10
select contract,
(select date_prolog from test where contract = 'yes') as date_prolog,
hours
from test
where contract = 'no'

Resources