Pivot selected columns into rows with SQL Server [closed] - sql-server

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;

Related

How to update dates in a table so that each row's date is pushed ahead by 1 day? [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 12 months ago.
Improve this question
I have a table whose Date column needs pushing ahead by 1 day.
My update query is:
UPDATE TABLENAME
SET DATECOL=DATECOL+1
Is this correct approach? Or do I need to use CTE, for example:
;WITH CTE AS (
SELECT ID, DATECOL
FROM TABLENAME)
UPDATE T
SET T.DATECOL=CTE.DATECOL+1
FROM TABLENAME T
JOIN CTE ON T.ID=CTE.ID
To add a value to any part of date you can use DATEADD function. In your case the part time is DAY.
UPDATE TABLENAME
SET DATECOL=DATEADD(DAY, 1, DATECOL)

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

How to select a specific row in Microsoft SQL Server 2008 [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 6 years ago.
Improve this question
Im using Microsoft SQL Server 2008 and i wanted to dump something from the database.
Its holding over 585k users.
I wanted to ask how i can select a specific row in a column
Like the column is named "User_ResetKey" in the database US_HBS_MEMBERS the table would be US_UserInfo, im really a noob in that maybe someone can help me the row number would be 123921
I mean how i can fetch data what is in the row number 123921?
regards,
jamsb
via using
Row_number()
here you are ,
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY [User_ResetKey] ) AS rownumber,
*
FROM [US_HBS_MEMBERS].[dbo].[US_UserInfo]
) AS myTable
WHERE rownumber = 123921
supposed your schema is 'dbo'.

how to select content in database? [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 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;

Resources