|
|
|
|
|
|
|
Question of the Day |
Today's question (by Steve Jones - SSC Editor): | |
Avoiding the Vector | |
I have an R data frame that looks like this:
> travel Passenger FlightDate Destination Miles Dollars 1 Steve 20180225 LHR 11789 1100 2 Steve 20180512 LHR 10989 1500 3 Steve 20180620 LHR 11789 1800 4 Steve 20180830 LHR 11789 1100 5 Steve 20181015 LHR 9678 2700 6 Steve 20181212 LHR 10520 1500 7 Steve 20180810 MSY 2427 440 8 Steve 20180225 OSL 1502 210 9 Steve 20180225 DCA 1475 310I want to extract out the mileage for the first 6 rows to a separate data frame. I decide to run this: > lhr.flights = travel[1:6,"Miles"]However, this gives me a vector that is shown here: > lhr.flights [1] 11789 10989 11789 11789 9678 10520I want these in a data frame. How should I alter the lhr.flights statement to get this? > lhr.flights Miles 1 11789 2 10989 3 11789 4 11789 5 9678 6 10520 | |
Think you know the answer? Click here, and find out if you are right. |
Yesterday's Question of the Day (by Steve Jones - SSC Editor) |
The Partial Computed Column I want to add this column to my table. What happens when I run this? ALTER TABLE dbo.Activities ADD ProdOneCount AS CASE WHEN ProductID = 1 THEN CallCount END; GO Answer: The column is created successfully Explanation: This works fine. There is no requirement to have an ELSE clause. Ref: Ref: Alter Computed Column Definition - https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-table-computed-column-definition-transact-sql?view=sql-server-2017 |
Database Pros Who Need Your Help |
Here's a few of the new posts today on the forums. To see more, visit the forums. |
SQL Server 2017 - Administration |
DBA vs Developers - Whats difference between sql dba and sql developers? How do dbas and developers usually get assigned work? Do dba's assign developers work? |
SQL Server 2017 - Development |
Parsing SQL Data between Tables for a certain Output - Hello, Extremely new to SQL here - bare with me. I'm looking for some insight on how to accomplish a report I'm trying to make. I need to take data from 1 table, select it but after the selection of data, I want to parse a certain column, run it against another table to change […] |
SQL Server 2016 - Administration |
OLDEST_PAGE log reuse wait - In SQL Server 2016 SP2, we had a transaction log that had a truncation wait for OLDEST_PAGE indefinitely, until the disk filled up. We ran a CHECKPOINT manually and it was able to truncate. Some documentation stated this was due to indirect checkpoints, so we changed the Target Recovery Time from 60 to 0 and […] |
SSIS Deployment w params - Hi I have a simple package that exports data via ftp using a dynamic path & filename. I created it on my server so I know it won't work on the test server Because of folder and the DB connection and table exported. How do I set project parameters when I deploy it please;is it […] |
User Access - Hi, I have an Windows 2012 R2 Server hosting a 2016 SQL Server, I have admin access to the windows server. The SQL server only has the default sa admin user account. I want to use VBA to create a connection to the server to return some data to excel using the following connection statement; […] |
SQL Server 2016 - Development and T-SQL |
Selecting data from two columns - The table has many columns, two of which are mutually exclusive, LocationNo and assetNo, so for any record only one of these columns contains a value, while the other is null. It's easy enough to do this: isnull(LocationNo, AsstNo) as LocOrAsset, but I would like to prepend to this 'A:' or 'L:' Any smart, sneaky […] |
Exception handling for backup related errors. - Hi All, Need some help in exception handling. In below code, I want to know the reason why the backup is failing. For testing purpose, I have intentionally given wrong path of the backup file. i.e. Z: drive doesn't exist and when I run the backup command alone, it gives exact error message saying path […] |
SQL query help - I have a table like this: Year month col_abc1 col_abc2 col_abc3 col_abc4 col_processing 2019 1 a1 a2 a3 a4 abc2 2019 2 a8 a6 a2 a9 abc2 2019 3 a5 a6 a3 a8 abc3 ...and so on I have a requirement that for a year and month, i need to check value of col_processing like […] |
Administration - SQL Server 2014 |
DB Log File Location Error - Hi, I am taking full backup of db on remote location. The issue we are facing is that my backups are generating fine at remote address but while generating Log file for those backups, Maintenance plan history shows error that It cannot locate part of address. How this is possible that my backups are generating […] |
Error logs with Email Alerts - Is there a better way to Automate Monitoring SQL Server Error Logs with Email Alerts. This is what i found, unless anyone has a better solution than this? Thanks in Advance! https://www.mssqltips.com/sqlservertip/2307/automate-monitoring-sql-server-error-logs-with-email-alerts/ |
SQL Server 2008 Performance Tuning |
Help to optimize select query - Need help to rewrite the query for faster result. use ABC_DB; SELECT c.otherID, a.shortname, c.priority, c.amended_date, cast(c.SomeVarcharMaxColumn as xml) FROM [ABC_Schema].[ABC1_Table] a WITH (NOLOCK), [ABC_Schema].[ABC2_Table] b WITH (NOLOCK), [PQR_Schema].[PQR1_table] c WITH (NOLOCK) where cc.ManagerId = c.Id and a.ManagerId = c.ManagerId and a.shortname = 'ABC' and c.amended_date >= cast('2018-10-01 00:00:00' as DATE) --(amended_date is the datetime […] |
Help to optimize select query - Need help to rewrite the query for faster performance. use ABC_DB; SELECT c.otherID, a.shortname, c.priority, c.amended_date, cast(c.SomeVarcharMaxColumn as xml) FROM [ABC_Schema].[ABC1_Table] a WITH (NOLOCK), [ABC_Schema].[ABC2_Table] b WITH (NOLOCK), [PQR_Schema].[PQR1_table] c WITH (NOLOCK) where cc.ManagerId = c.Id and a.ManagerId = c.ManagerId and a.shortname = 'ABC' and c.amended_date >= cast('2018-10-01 00:00:00' as DATE) --(amended_date is the datetime […] |
Integration Services |
Refresh data warehouse with production data - Hello SSC, I want to create a package that refreshes the tables in my data warehouse with production (live) data. I have an SSIS package that simply TRUNCATES the tables and then reloads them (I did not write this package). I am not a fan of this method because we are reloading archived data for […] |
Difference between task time and sys.dm_exec_query_stats time - Hello I have a SQL task that ran through yesterday in around 23 minutes It executes an SP and performs a couple of updates If I look at the DMV stats, this task is is showing as taking around 20 hours! sys.dm_exec_query_stats time total_worker_time Also sys.dm_exec_procedure_stats There's only one execution for ths SP It's […] |
Design Ideas and Questions |
From cluster to single node - Hi all, We currently have a 2 node dev cluster which I need to dismantle and either keep only node 1 or move to a new server. I am an SQL noob and this is a good project for me to dip my toes into the SQL reality. I looked around for some info […] |
| |
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved. webmaster@sqlservercentral.com |