How to select a specific row in Microsoft SQL Server 2008 [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 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'.

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 delete top (1) row from SQL if row count reached to 10000 [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 1 year ago.
Improve this question
I have made fault history log into HMI through SQL database,
I am deleting top row by PLC TAG by using following code
DELETE TOP (10) PERCENT FROM [dbo].[ABC]
I want to delete first row while my row-count reached to 10000
in other way to say that ....
a new fault record add in log and first old record should delete and so on...
If I understansd you correctly, you need to number the rows using ROW_NUMBER() and then execute appropriate DELETE and INSERT statements:
DELETE t
FROM (
SELECT *, ROW_NUMBER() OVER (ORDER BY PLC DESC) RN
FROM [dbo].[ABC]
) t
WHERE RN >= 10000
INSERT [dbo].[ABC] (PLC) VALUES (...)

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.

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;

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