MGM 19
New Member
Hello everyone,
I once again have a problem :p I need to write a query to get the total amount of rows in a table. Problem is, the table name is dynamic and part of its value is stored in another table. Here's my query: - SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM CDT_DEM_Pages AS a
-
ORDER BY name
What I'm trying to do is to count the total amount of rows in a table named CDT_DEM_DATA_[blank] where [blank] is a name like "test" that is stored in CDT_DEM_Pages as a column (named alphanumericnam e). I'm not exactly sure how to append the alphanumericnam e column's data into the query dynamically to find the total amount of rows in it...
MGM out
4 1825 ck9663 2,878
Recognized Expert Specialist
Hello everyone,
I once again have a problem :p I need to write a query to get the total amount of rows in a table. Problem is, the table name is dynamic and part of its value is stored in another table. Here's my query: - SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM CDT_DEM_Pages AS a
-
ORDER BY name
What I'm trying to do is to count the total amount of rows in a table named CDT_DEM_DATA_[blank] where [blank] is a name like "test" that is stored in CDT_DEM_Pages as a column (named alphanumericnam e). I'm not exactly sure how to append the alphanumericnam e column's data into the query dynamically to find the total amount of rows in it...
MGM out
use dynamic query: -
declare @mytablename varchar(50)
-
-
set @mytablename = 'CDT_DEM_DATA' + '_Pages'
-
-
exec ('SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM ' + @mytablename + ' AS a
-
ORDER BY name')
-
-
set @mytablename = 'CDT_DEM_DATA' + '_NoPages'
-
-
exec ('SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM ' + @mytablename + ' AS a
-
ORDER BY name')
-
The values '_Pages' and '_NoPages' may be a variable.
You may also place the entire query in a variable - declare @strquery varchar(50)
-
-
set @strquery = 'SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM ' + @SomeVariableForYourTableName + ' AS a
-
ORDER BY name'
-
-
exec (@strquery)
-
-
Happy Coding...
-- CK
MGM 19
New Member
use dynamic query: -
declare @mytablename varchar(50)
-
-
set @mytablename = 'CDT_DEM_DATA' + '_Pages'
-
-
exec ('SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM ' + @mytablename + ' AS a
-
ORDER BY name')
-
-
set @mytablename = 'CDT_DEM_DATA' + '_NoPages'
-
-
exec ('SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM ' + @mytablename + ' AS a
-
ORDER BY name')
-
The values '_Pages' and '_NoPages' may be a variable.
You may also place the entire query in a variable - declare @strquery varchar(50)
-
-
set @strquery = 'SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM ' + @SomeVariableForYourTableName + ' AS a
-
ORDER BY name'
-
-
exec (@strquery)
-
-
Happy Coding...
-- CK
Well the problem with that is that the text that I need to append is not static and is actually a row inside another table (CDT_DEM_Pages) . That is to say, CDT_DEM_Pages has a column named alphanumericnam e that has text in it, this text need's to be appended to the end of [CDT_DEM_DATA_] so that I can get the data I need. The bold part in the query below is what needs to be changed: - SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM CDT_DEM_Pages AS a
-
ORDER BY name
MGM out
ck9663 2,878
Recognized Expert Specialist
Well the problem with that is that the text that I need to append is not static and is actually a row inside another table (CDT_DEM_Pages) . That is to say, CDT_DEM_Pages has a column named alphanumericnam e that has text in it, this text need's to be appended to the end of [CDT_DEM_DATA_] so that I can get the data I need. The bold part in the query below is what needs to be changed: - SELECT id, name,
-
(SELECT COUNT(*) AS amtColumns
-
FROM CDT_DEM_Columns
-
WHERE (pageid = a.id)) AS amtColumns,
-
(SELECT COUNT(*) AS amtRows
-
FROM CDT_DEM_DATA_+a.alphanumericname
-
WHERE (pageid = a.id)) AS amtRows
-
FROM CDT_DEM_Pages AS a
-
ORDER BY name
MGM out
I would need:
1. The datatype of a.id
2. The actual fieldname of a.alphanumericn ame
-- CK
MGM 19
New Member
I would need:
1. The datatype of a.id
2. The actual fieldname of a.alphanumericn ame
-- CK
a.id is an integer and the identity column for a (CDT_DEM_Pages)
a.alphanumeric is an nvarchar(50) that is NOT NULL
MGM out
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: freeagent |
last post by:
Help!!
I am a complete Access newbie and I have to concatenate about 30
tables into one large table. All these tables have the same column
headings as each other.
For example, I have TABLE 1 which contains COLUMN1, COLUMN2, COLUMN3
....
|
by: Access Newbie |
last post by:
I'm using Access 2000 and I'm trying to create a pass-through query to
append all the data from a local table to a remote table.
I'm using the SQL query editor in MS Access to create the query (I
don't want to do this in VB code).
I've set up the ODBC connection string in the query properties, which
has been tested and works:...
|
by: oasd |
last post by:
I'm having difficulty appending data.
I have an import macro (using the Transferspreadsheet function) to import
data from an excel spreadsheet (located in a USB attached to the pc) to an
access database.
The data in the USB has addtional info to be added to the respective record
in the database. The problem is that the data is not appended to...
|
by: MLH |
last post by:
I have a query, qryAppend30DayOld260ies that attempts to append
records to tblCorrespondence. When run, it can result in any of the
following: appending no records, appending 1 record or appending
many records. Two of the target fields in tblCorrespondence receiving
values in the append operation are and . For
any given VehicleJobID value, I...
|
by: PC Datasheet |
last post by:
Looking for suggestions ----
A database was designed for a national automobile inspection program. In
it's simplest form, the database has two tables:
TblOwner
OwnerID
<Year/Make/Model owned by owner, Owner name/address, etc)
TblInspection
InspectionID
| |
by: deejayquai |
last post by:
Hi
I'm still trying to solve my problem. I have two tables- students and
activity assessments, they're linked one-to-many. From a
lookup/combo/list I'd like to be able create a series of new
activity assessment records each with the activity name field populated
per student or group of students.
i.e. Bob has no activity assessments...
|
by: Daz |
last post by:
Hi everyone!
Is it possible to take a line of text like so:
<tr><td>title1</td><td>title2</td><td>title3</td><td>title4</td></tr>
And append it to a DOM node such as this:
var nodeToAppendTo = document.getElementById('tbody');
|
by: Nathan Guill |
last post by:
I have an interface that works with an Access back-end. I would like to
store and/or load user defined query strings per each user (i.e. no user can
access another's queries). The idea I had was a "table" stored with the C#
front-end (not in the Access database), but don't know if this is even
possible. If it is, can someone let me know...
|
by: nbardach |
last post by:
Hope this finds everyone well. Happy New Year!
I'm trying to build a Loop for a set of dropdown menus I'm inserting into a form.
Basically, the client has to be able to select 1 to 20 donors with the dropdown options (member names) pulled from the DB. When the client is editing a donation record, she needs to be able to view the correct...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |