We help IT Professionals succeed at work.
Get Started

Are wildcards available for SELECT and FROM when creating a TSQL query

181 Views
Last Modified: 2012-05-07
Hello all!

I am new to this field and am trying to generate a view that will pickup some data from all tables from my database appDB that start with PL01, but it seems I cannot use _ as a wildcard neither in the SELECT line nor in the FROM line. I have about 40 different PL01cc00 tables, where cc indicates the company code for each separate company.

Is that correct? And if these wildcards are not usable, is there a workaround I could use?

Also, is the syntax of my WHERE clause correct, as I never get that far?

Any assistance is greatly appreciated! Many txs
USE [appDB]
	GO
	/****** Object:  View [dbo].[SupCust_PL]    Script Date: 08/26/2009 15:44:59 ******/
	SET ANSI_NULLS ON
	GO
	SET QUOTED_IDENTIFIER ON
	GO
	ALTER VIEW [dbo].[SupCust_PL_TEST]
	AS
	SELECT     TOP (100) PERCENT appDB.dbo.PL01__00.PL01001 AS SupplierCode, appDB.dbo.PL01__00.PL01002 AS SupplierName, systemDB.dbo.ScaCompanies.CompanyCode as CompanyCode
	FROM         appDB.dbo.PL01__00, systemDB.dbo.ScaCompanies
	where		 systemDB.dbo.ScaCompanies.CompanyCode=substring([appDB.dbo.PL01__00],17,2)
    ORDER BY     CompanyCode, SupplierCode

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE