Questions tagged [tablename]

143 questions
223
votes
10 answers

A table name as a variable

I am trying to execute this query: declare @tablename varchar(50) set @tablename = 'test' select * from @tablename This produces the following error: Msg 1087, Level 16, State 1, Line 5 Must declare the table variable "@tablename". What's the…
SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
66
votes
8 answers

Entity Framework Core RC2 table name pluralization

Is there a way to do what this code did in EF Core RC 2? protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Conventions.Remove(); }
Paul Speranza
  • 2,302
  • 8
  • 26
  • 43
57
votes
1 answer

How to select from MySQL where Table name is Variable

I have a case where getting the table name should be from a set variable like: SET @ID_1 = (SELECT ID FROM `slider` LIMIT 0,1); SET @Cat = (SELECT Category FROM `slider` LIMIT 0,1); select * from @Cat where ID = @ID_1 but doing that way MySQL…
Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89
37
votes
2 answers

Loop on tables with PL/pgSQL in Postgres 9.0+

I want to loop through all my tables to count rows in each of them. The following query gets me an error: DO $$ DECLARE tables CURSOR FOR SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' ORDER BY…
Totor
  • 483
  • 1
  • 4
  • 5
16
votes
2 answers

mysql (5.1) > create table with name from a variable

I'm trying to create a table with a name based on the current year and month(2011-09), but MySQL doesn't seem to like this. SET @yyyy_mm=Year(NOW())+'-'+Month(NOW()); CREATE TABLE `survey`.`@yyyy_mm` LIKE `survey`.`interim`; SHOW TABLES IN…
Jakob Jingleheimer
  • 30,952
  • 27
  • 76
  • 126
14
votes
4 answers

Using mysqlimport where the filename is different from the table name

I've been playing with mysqlimport and I've run into the restriction where the filename has to be the same as the table name. Is there any way to work round this? I can't rename the file as it is used by other processes and I don't want to copy the…
Mike Q
  • 22,839
  • 20
  • 87
  • 129
13
votes
3 answers

Use Mysql lower_case_table_names to 1

I have installed mysql v5.5.17 in linux using yum, now i want default lowercase table names so i have added set-variable = lower_case_table_names=1 in /etc/my.cnf but if i do that then i could not start mysqld service. Mysql logs says unknown…
Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
11
votes
4 answers

Query a table that has spaces in its name

I have a situation, I have a Access table named Gas Flow Rates that I want to add records. When I try to run my insert query for a similar table Common Station, I get the following error: "error hy000: syntax error, in query incomplete query…
LaDante Riley
  • 521
  • 4
  • 14
  • 26
10
votes
6 answers

Excel Return Table name using Formula?

I was wondering if there is anyway to return the name of the table using a formula? I was working on a way to break down a few thousand addresses into there perspective column of information. ie.. #, Street, City, State, Zip-code and Phone#. The…
Mouthpear
  • 199
  • 1
  • 3
  • 13
9
votes
1 answer

How to get the table name from a field in a join query with MSSQL? (mysql_field_table equivalent)

I'm doing a query manager in Delphi using ADO, I need to know all fields that will be returned by a query, does no matter how complex and how much joins they will have. I want to call a function, that return to me, all fields that will be returned…
user2092868
  • 273
  • 3
  • 18
8
votes
1 answer

Left join with dynamic table name derived from column

I am new in PostgreSQL and I wonder if it's possible to use number from table tbc as part of the table name in left join 'pa' || number. So for example if number is 456887 I want left join with table pa456887. Something like this: SELECT tdc.cpa,…
Lubos K.
  • 559
  • 2
  • 8
  • 16
8
votes
1 answer

How can I find out what SQL Server tables are linked to MS Access?

I inherited a MS Access front-end that has linked tables to SQL Server. The linked table names in MS Access do not match the table names in SQL Server. How can I find out what SQL server tables are actually linked to MS Access? Also, if I didn't…
Tuan
  • 514
  • 3
  • 8
7
votes
1 answer

Is it correct that "ResultSet.getMetaData.getTableName(col)" of postgresql's jdbc driver is always returning an empty string?

When I use postgresql, I found following code: Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from t"); String tableName = rs.getMetaData().getTableName(1); System.out.println(tableName); It prints an empty…
Freewind
  • 193,756
  • 157
  • 432
  • 708
7
votes
4 answers

How to get table name from column in DB2?

I need the DB2 SQL query to find the table/tables from column name. I have the column name but don't have table name which this column belongs to.
AAA_king
  • 91
  • 1
  • 1
  • 2
6
votes
3 answers

Safe way to use table name as parameter in JDBC query

What is the safe way how to put table name as parameter into SQL query? You cannot put table name as parameter using PreparedStatement. Concatenating string to execute query with dynamic table name using Statement is possible, however it is not…
Martin
  • 149
  • 1
  • 2
  • 7
1
2 3
9 10