logo
down
shadow

Selecting columns from string


Selecting columns from string

By : Rafael Cabeza
Date : October 15 2020, 06:10 AM
hope this fix your issue i have a string with my needed columns, which i want to select. For example: , You can try to use dynamic sql
code :
DECLARE @SQL VARCHAR(MAX)=  'SELECT '+  @sqlstring + ' FROM MyTable '
EXEC (@SQL)  


Share : facebook icon twitter icon
Selecting string columns in pandas df (equivalent to df.select_dtypes)

Selecting string columns in pandas df (equivalent to df.select_dtypes)


By : DEPSI
Date : March 29 2020, 07:55 AM
will be helpful for those in need Given a Pandas df with different data types, df.select_dtypes can be very useful to keep only desired columns or to get rid of unwanted columns for a particular application. , Option 1
Using df.applymap and type, and equating to str:
code :
In [377]: (df.applymap(type) == str).all(0)
Out[377]: 
dict_col    False
int_col     False
str_col      True
dtype: bool
In [342]: df.applymap(lambda x: isinstance(x, str)).all(0)
Out[342]: 
dict_col    False
int_col     False
str_col      True
idx = ... # one of the two methods above
df_new = df[df.columns[idx]]
df_new = df[df.columns[~idx]]
SQL Query to convert TIMESTAMP to String while selecting the columns

SQL Query to convert TIMESTAMP to String while selecting the columns


By : Naeem Chap
Date : March 29 2020, 07:55 AM
I hope this helps . I am using DB2 database. I have a table and it has two columns as below: , Aniket V's suggestion helped me in figuring out the solution.
code :
select  TO_CHAR(CRDATTIM,'YYYY-MM-DD-HH24.MI.SS.FF6') as CRDATTIM ,recordcd from sample  ;
regex selecting columns that contain string except one

regex selecting columns that contain string except one


By : user7337185
Date : March 29 2020, 07:55 AM
like below fixes the issue I have a pandas DataFrame as shown below. I want to select all columns that end with "_cd" or "_ind" except for the column "final_ind". How can I do that? , You can use filter with regex like so:
code :
df.filter(regex='^(?!final).*(_cd|_ind)$')

# var2_ind  var3_cd
#0      a4       10
#1      a3        5
#2      b1        7
Selecting multiple columns to one string (by date)

Selecting multiple columns to one string (by date)


By : Iris Marie
Date : March 29 2020, 07:55 AM
seems to work fine My pricelist table looks like this: , I would use row_number() function :
code :
select concat(itemcode, ':', 
       stuff( ( select top (1) with ties ',(' +concat(VendorCode, ',', UnitCost ,',', cast(StartingDate as date)) +')'
                from Pricelist
                where itemcode = p.itemcode
                order by row_number() over (partition by VendorCode order by StartingDate desc)
                for xml path('')
               ), 1, 1, ''
            ))
from Pricelist p
group by itemcode;
Selecting rows on basis of the string length of two columns

Selecting rows on basis of the string length of two columns


By : user178088
Date : March 29 2020, 07:55 AM
This might help you @agstudy got the most important part. I would add that str_sub (from the stringr package I assume) is not doing anything useful here. Last, you could use subset to avoid the repetitive use of df$. So you can do:
Related Posts Related Posts :
  • SQL Server 2005 triggered audit tables moved to SQL Server 2008, now trigger does not respond when trying to insert row
  • Using NHibernate to insert/update using a SQL server-side DEFAULT value
  • How to convert column type from varchar to date in PostgreSQL?
  • Combining the UNIQUE and CHECK constraints
  • MS SQL Server decimal data type rounds up
  • sp_addlinkedserver on sql server 2005 giving problem
  • Transitive SQL query on same table
  • Strange use of the index in Mysql
  • Oracle - pl sql selecting from SYS_REFCURSOR
  • Broken count(*) after adding LEFT JOIN
  • Product Catalog Schema design
  • ODBC Connection String Problem
  • What's a reasonable number of rows and tables to be able to join in MySQL?
  • CFQuery where param
  • Split a Column in SQL Server
  • What does the % symbol do at the end of a string in SQL?
  • sql server 2005 express - Invalid Object Name error
  • Merge overlapping date intervals
  • Loop Control within a DataflowTask in ETL
  • SQL | How to always round up regardless of the last integer value, even when that may be 0
  • how to convert any char to - in sql server?
  • how to create function in postgres
  • Need to speed up the results of this SQL statement. Any advice?
  • How do I retrieve 10 days data up to date 'XYZ' from mysql with Perl when some days data are missing, i.e. public holida
  • How to export data with Oracle SQL Developer?
  • Aggregate SQL column values by time period
  • Are soft deletes a good idea?
  • DBCC SHRINKFILE 1 sproc for multiple databases
  • SQL VBA syntax issue
  • How to select a subset of results from a select statement
  • Oracle SQL: ROLLUP not summing correctly
  • How to select the second row in a table without where clause
  • How to compare the date in SQL
  • Sql Server xml column with Entity Framework - how to keep insignificant whitespaces
  • Finding all related tables to a given table
  • Two different tables or just one with bool column?
  • Rotating sql table
  • How i can execute function?
  • How to write an error message from an BCP operation to a log file and stop processing the batch file.
  • Does MySQL have an equivalent of SQL Server "indexed views"?
  • Can i use MAX function for each tuple in the retrieved data set
  • Is there a way to make Identity Specification show up in the table designer next to the Allow Nulls column?
  • How to pass a date in query
  • oracle sql listagg
  • how to use a parameterized function for the Default Binding of a Sql Server column
  • Cassandra/HBase or just MySQL: Potential problems doing the next thing
  • 32bit to 64bit sql server 2008 database conversion
  • How to count on DISTINCT ON without subquery
  • SQL: changing IN to EXISTS
  • I need to convert this string to datetime in SQL Server
  • noSQL/SQL/RoR: Trying to build scalable ratings table for the game
  • Should I include user_id in multiple tables?
  • sql in ms-access
  • Which data type saves more space TINYTEXT or VARCHAR for variable data length in MySQL?
  • Select Max number with another column
  • SQL: Having a primary key also be a foreign key
  • PostgreSQL String search for partial patterns removing exrtaneous characters
  • sql query for fetching 10 rows with near values
  • Temporary intermediate table
  • Finding employees specific to department in SQL Server 2000
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk