Building SQL Strings From Variables

Dec 9, 2006

Disclaimer... I am very new to SQL server!

I am trying to create a stored proc. I am passing in some variables which are used as the "data" side of where clause tests, but I also want to pass in a couple of variables to be the variable side of the where clause test, can it be done?

i.e. select id from table where a=1 and b=2 order by my_order_field

becomes

select id from table where a=@data1 and b=@data2 order by @my_variable_field

and I call the sp with exex sp 1,2,my_order_field

Any clues?

View 10 Replies


ADVERTISEMENT

Building Dynamic SQL Query Strings

Jan 17, 2008

Let me start by asking that no one try to convince me to use Stored Procs.  The examples below are a lot more simplistic then my real world code and it just gets too complicated to try to manage the quantity of SPs that I would need.
I have an application that displays a lot of data and I've created a system for users to filter the data using checkboxlist controls, dropdown controls, etc.  From this, I have a "core" query that selects the fields that display in my GridView.  It has a base Select clause, From clause and Where clause.  From this I then add more to the Where clause to apply these filter values.
Here's an example "core" query:
SELECT Profile.FirstName, Profile.LastName, Project.ProjectNameFROM Profile, ProjectWHERE Profile.ProjectCode = Project.ProjectCode
From this if a user want's to only display profiles from NC, they could select that from the CBL and the query would be modified to:
SELECT Profile.FirstName, Profile.LastName, Project.ProjectNameFROM Profile, ProjectWHERE Profile.ProjectCode = Project.ProjectCodeAND Profile.State IN ('NC')
My code would add the last line above since the user specified that they only wanted NC profiles.
This is very simple and I have this already going on with my application.  Here's the problem.  In order to accommodate all of the various filters, I have to inner join and left join a bunch of various tables.  Many times I include tables that have no data to display or filter on and therefore impacts performance.  Here's an example:
SELECT Profile.FirstName, Profile.LastName, Project.ProjectNameFROM Profile, Project, AgentWHERE Profile.ProjectCode = Project.ProjectCodeAND Profile.AgentID = Agent.AgentID
From the query above, I have included the Agent table that holds the agent's contact information.  One of my filters allows the user to type in an agents name to find all profiles assigned to it.  Here's what that would look like:
SELECT Profile.FirstName, Profile.LastName, Project.ProjectNameFROM Profile, Project, AgentWHERE Profile.ProjectCode = Project.ProjectCodeAND Profile.AgentID = Agent.AgentIDAND Agent.Name = 'Smith, John'
You can see now that it was necessary to have the Agent table already joined into the query so that when I used the agent name filter, it wouldn't crash out on me.
The obvious thing would be to only include the Agent table when searching for an agent name.  This is ultimately what I'm looking to do, but I need a solid method to go about doing this.  Keep in mind that I currently have 16 tables in my "core" query and many of those are not needed unless the filters call for it.
If anyone has any ideas on how to simplify this process I'm selcome to suggestions.  We're using SQL 2000, but are looking to upgrade to SQL 2005, if that makes any difference.  I know that the way I do table joins is compliant with SQL 2005 and I'm certainly open to suggestions that will make it forward compatible.
This app is using .NET 2.0 and written in VB.NET.  Thanks for any help!

View 14 Replies View Related

Loops And Building Comma Delimited Strings

Oct 9, 2006

The problem:

I have 2 tables, with a one to many relationship - lets say customers, and order items.

Each order record has a field that is meant to be a comma delimited list (they are reference numbers) that is driven by the quantity field. So, say in the order record, an item has a quantity of 3. The reference number will look like this:

1, 2, 3

And if the next order item for that customer has a quantity of 4, the reference number value is

4, 5, 6, 7

And the final item with quantity of 2:

8, 9

Reference numbers can either be auto assigned (and are in my web application) or manually set. If manually set they will NOT be numeric.

In my web application, it is possible for users to return to a customer's order and edit a line item. My problem is when users changes the quantity of an item, and I have to reset the reference numbers.

If the quantity of line item 2 changes from 4 to 3, I need to reset all the values for that, and any other, order item that comes after it:

4, 5, 6 (2nd)
7,8 (3rd with same quantity of 2).

I felt a cursor would be the best way to handle this. But I am having trouble re-assigning my variable to be the next number in the series when the cursor is running.

This is what I have so far. The print lines and hard coded values are for debugging purposes only.

DECLARE @NumberingType varchar(10)
DECLARE @TotalSum int
DECLARE @DoorLineItemID int
DECLARE @Quantity int
DECLARE @SeedInt int


SET @SeedInt = 1

SELECT @TotalSum = SUM(Quantity) FROM DoorLineItems WHERE UniversalOrderID = 12345

DECLARE UpdateRefCursor CURSOR FOR
SELECT DoorLineItemID, Quantity FROM DoorLineItems WHERE UniversalOrderID = 12345 AND NumberingType = 1

OPEN UpdateRefCursor

FETCH NEXT FROM UpdateRefCursor INTO @DoorLineItemID, @Quantity
DECLARE @RefNumberLine varchar(1024)
SET @RefNumberLine = ''

WHILE @@FETCH_STATUS = 0
BEGIN

WHILE @SeedInt <= @Quantity
BEGIN

SET @RefNumberLine = @RefNumberLine + CONVERT(varchar, @SeedInt, 101) + ', '
SET @SeedInt = @SeedInt + 1

END

PRINT @RefNumberLine

SET @SeedInt = @Quantity + @SeedInt
PRINT 'new seed: ' + CONVERT(varchar, @SeedInt, 101) + 'Quantity ' + CONVERT(varchar, @Quantity + @SeedInt, 101)


FETCH NEXT FROM UpdateRefCursor INTO @DoorLineItemID, @Quantity


END

CLOSE UpdateRefCursor
DEALLOCATE UpdateRefCursor


This returns the same delimited string for X number of items. So I'm getting this:

1,2,3
1,2,3
1,2,3


When I really want the results described above.

What am I doing wrong?

Thanks!

View 2 Replies View Related

Building Query Strings Within Stored Procs - Good Or Evil?

Feb 4, 2008

I ran across this technique being used in an application the other day. It seems not a good idea to me. What do you think?

1. The proc builds a basic query, nothing real fancy, into a string variable called @SQL defined as varchar 2000. Depending on the result desired, the group by clause can be one of three different sort orders.

2. The string is executed via EXEC @SQL.

It seems to me that the whole process can eliminate the EXEC and just use some other construct. All the parameters are passed in via the initial call to the stored proc. It also seems that every time this is executed it will result in a new query compile and cache useage, no matter what. Wasteful? Should I take the developers aside and knock heads? I think the app was coded by some folks who were rookies then but may be willing to crack open their code. Or, am I the one that is a rookie?

Thanks for your inputs.

View 11 Replies View Related

Putting Variables In SQL Strings

Apr 11, 2008

Atm this is my Test SQL String

"INSERT INTO tblPDFFiles (fileType, PDFcontent) SELECT 'Test' AS Expr1, BulkColumn FROM OPENROWSET(BULK 'F:websitesTESTarchived est.pdf', SINGLE_BLOB) AS BLOB"

When I try to put in a variable as follws

"INSERT INTO tblPDFFiles (fileType, PDFcontent) SELECT '" + @[User::MyFileValue] + "' AS Expr1, BulkColumn FROM OPENROWSET(BULK 'F:websitesTestarchived est.pdf', SINGLE_BLOB) AS BLOB"

I keep getting errors Saying it contains an illegal escape sequence of w any ideas ?

Btw the above is used as an expression

View 4 Replies View Related

Variables In Query Strings (that Are Stored In A Db)

Oct 28, 2004

Hi all,

If I have a query string that is to be stored in a database, for example


Code:

SELECT prod_id, prod_name, prod_desc FROM products WHERE prod_id = 'variable'



how can I put a variable identifier into this string so that when I need to run the query I call it from the database and simply insert the relevant variable in the correct place.

Is there an appropriate way of doing this in MS SQL Server?

Thanks

Tryst

View 1 Replies View Related

Concatenate Strings After Assigning Text In Place Of Bit Strings

Feb 19, 2007

I have a whole bunch of bit fields in an SQL data base, which makes it a little messy to report on.

I thought a nice idea would be to assigne a text string/null value to each bit field and concatenate all of them into a result.

This is the basic logic goes soemthing like this:


select case new_accountant = 1 then 'acct/' end +

case new_advisor = 1 then 'adv/' end +

case new_attorney = 1 then 'atty/' end as String

from new_database

The output would be

Null, acct/, adv/, atty, acct/adv/, acct/atty/... acct/adv/atty/

So far, nothing I have tried has worked.

Any ideas?

View 2 Replies View Related

Execute DTS 2000 Package Task Editor (Inner Variables Vs Outer Variables)

Sep 4, 2006

Hi,

I am not comfortable with DTS 2000 but I need to execute a encapsulated DTS 2000 package from a SSIS package. The real problem is when I need to pass SSIS variables to DTS 2000 package. The DTS 2000 package have 3 global variables that I can identify on " Execute DTS 2000 Package Task Editor - Inner Variables ". I believe the SSIS variables must be mapped on " Execute DTS 2000 Package Task Editor - OuterVariables ". How can I associate the SSIS variables(OuterVariables ) to "Inner Variables"? How can I do it? Much Thanks.

João





View 8 Replies View Related

How To Design A Package With Variables So That I Can Run It By Dos Command Assigning Values To Variables?

Jan 24, 2006

Hi,

I would like to design a SSIS package, which have couple of variables. It loads a xls file specified in a variable [varExcelFileFullPath] .

I will run it by commands: exec xp_cmdshell 'dtexec /SQL ....' (pls see an example below).

It seems it does not get the values passed in for those variables. I deployed the package to a sql server.

are there any grammar errors here? I copied it from dtexecui. It worked inside Dtexecui not in dos command.

exec xp_cmdshell 'dtexec /SQL "LoadExcelDB" /SERVER test /USER *** /PASSWORD ****

/MAXCONCURRENT " -1 " /CHECKPOINTING OFF /REPORTING EW

/LOGGER "{6AA833A1-E4B2-4431-831B-DE695049DC61}";"Test.SuperBowl"

/Set Package.Variables[User::varExcelFileName].Properties[Value];"TestAdHocLayer"

/Set Package.Variables[User::varExcelWorkbookName].Value;"Sheet1$"

/Set Package.Variables[User::varExcelFileFullPath].Value;"D: estshareTestAdHocLayer.xls"

/Set Package.Variables[User::varDestinationTableName].Value;"FeaturesTmp"

/Set Package.Variables[User::varPreSQLAction].Value;"delete from FeaturesTmp"

'



thanks,



Guangming

View 2 Replies View Related

Building A Community

Feb 1, 2007

Hi! Hello. I have now started to build my own community. And I have some questions on the database.For the users to login I use the login control and all the users information is stored in the ASPNETDB.MDF database.In the web.config file I have created some profiles for saving some information about the users (Name, Birth, Town) and so on.Now. All the users in this community will have their own profile page, Guestbooks ++.So I was wondering if I should create tables for all features like guestbook, profile pages or should I do this by using Profile (ASP.NET).How many users does ASPNETDB support?. 

View 1 Replies View Related

Building A Date In SQL

Jul 31, 2007

Is there any sql method that takes 3 parameter like, day, month and year . And return me the date.
For example
   function(10,3,2007) and it returns  10-03-2007
 
Thanks,
 

View 2 Replies View Related

Building Treeview

Jan 3, 2008

 
userfeatureuserName  featureIda          1a          5b          1b          5b          9c          5 c          9
menuid   Pid  Name1         Administrator2     1   Create User3     1   Delete USer4     1   View log5         WSR6     5   X7     5   X8     5   X9         Manager10    9   Y11    9   Y
 Using the above table i want to create a treeview ie based on the user login. Please let me know if there is any previous sample to this situation.
 
 

View 2 Replies View Related

Building Search

Apr 15, 2004

Hi

I've never done this before and I have all kinds of issues conflicting in my head (search rank, noise words, injection attacks ..etc). simply i need to search several columns in a table in the database using one search text (just like the simple search in Google). if multiple words are you used then the search should search for each of them. also manage to ignore noise words and other issues.

what is the best way of doing this? I looked at FTS in SQL 2000 but didn't know how to handle all the above mentioned issues. this should be simple, right? but i have been looking all day. I guess i don't know what im looking for because i've never implemented a web search b4.

please help

p.s. I know t-sql and asp.net/c# well.

View 1 Replies View Related

Building A Where Clause

Mar 9, 2006

I am not very experienced with stored procs and I'm attempting to write my first one. I am writing a search page via aspx and that page will call my proc and depending on the input parameters, the proc will return the search results. To do this I have built a where clause string but I don't know how to (if it's even possible) make this variable part of my query. Can anyone tell me a way to make the following work (input params left out to conserve space)?
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET ANSI_WARNINGS OFF
SET @where = ''
IF @JobNoStart !='' SET @where =+ ' AND LJOB BETWEEN @JobNoStart AND @JobNoEnd'
IF @OrderDateStart !='' SET @where =+ ' AND JOBDATE BETWEEN @OrderDateStart AND @OrderDateEnd'
IF @DueDateStart !='' SET @where =+ ' AND DUEDATE BETWEEN @DueDateStart AND @DueDateEnd'
IF @ProofDateStart !='' SET @where =+ ' AND PROOFDUE BETWEEN @ProofDateStart AND @ProofDateEnd'
IF @CloseDateStart !='' SET @where =+ ' AND CLOSEDATE BETWEEN @CloseDateStart AND @CloseDateEnd'
IF @CogsDateStart !='' SET @where =+ ' AND COGSDATE BETWEEN @CogsDateStart AND @CogsDateEnd'
IF @ProductName !='' SET @where =+ ' AND PRODUCT = @ProductName'
IF @CustomerNumber !='' SET @where =+ ' AND FCUSTNO = @CustomerNumber'
IF @SalesPerson !='' SET @where =+ ' AND FSALESPN = @SalesPerson'
IF @CSR !='' SET @where =+ ' AND JOBPER = @CSR'
IF @Closed = 0 SET @where =+ ' AND CLOSEDATE IS NOT NULL OR CLOSEDATE IS NULL'
ELSE IF @Closed = 1 SET @where =+ ' AND CLOSEDATE IS NULL'
ELSE IF @Closed = 2 SET @where =+ ' AND CLOSEDATE IS NOT NULL'
IF @Canceled = 0 SET @where =+ ' AND CANCDATE IS NOT NULL OR CANCDATE IS NULL'
ELSE IF @Canceled = 1 SET @where =+ ' AND CANCDATE IS NOT NULL'
ELSE IF @Canceled = 2 SET @where =+ ' AND CANCDATE IS NULL'
IF @FinalShip = 0 SET @where =+ ' AND FINALSHIP IS NOT NULL OR FINALSHIP IS NULL'
ELSE IF @FinalShip = 1 SET @where =+ ' AND FINALSHIP IS NOT NULL'
ELSE IF @FinalShip = 2 SET @where =+ ' AND FINALSHIP IS NULL'
SELECT LJOB, DUEDATE, FCOMPANY, ID, QUAN WHERE LJOB IS NOT NULL @where


END

View 4 Replies View Related

Building Sql Statements

Jan 6, 2003

Hi,

I am having some problems trying to build an sql statement from more than one statement.

Here is the statement

select 'Insert App_Column (Table_ID, Column_Type_Transformation, Column_Name, )
Values (@table_ID,' ,'NULL,', name from payatwork..syscolumns where id in (
select id from payatwork..sysobjects where name like 'Employee_Profile')
order by colorder, ')'

What I am finding is that the bracket at the end of the statement is not appearing - how do I append statements to the end of this sql statement (i've tried various combinations of the + sign and the comma without success.

thanks,

Jim

View 4 Replies View Related

Building An NT Box To Host SQL 7

Oct 25, 1999

I'm in the midst of planning how to build an NT box to host SQL 7.0 and was wondering if there is any advantage to segregating the RAID 5 Array (5 x 18GB drives) into numerous *logical* partitions to separate database and log files (I can't see what advantage there would be if the disks are all on the same array, but..)

If anyone has any pointers or links to recommended NT configurations for hosting SQL, I'd appreciate hearing them.

TIA,
RM

View 1 Replies View Related

SQL Newbie Needs Help Building SP

Sep 18, 1999

Help Please - JMail - SQL SPs - Confirmation Email

I'm at the last stage of my current project and an totally stuck.

I'm trying to build the body of a order processing request email. For security reasons I wish to use a SP to build and send the email. (therefore no sensitive data gets passed to the client)

I have the JMail Object running properly on the server. It collects and sends the email in the normal course of the transaction from the client. Problem is that I cannot figure out how to properly build the body of the email in the SP.

I'm looking to do add the following to a single SQL SP variable to stuff in the Jmail Object to be sent. The content of the variable should look something linke the following:
-----------------------------------------

"Order placed:" = orders.date + '<cr>?'
customers.name<cr>
orders.shippingaddress<cr>
orders.billingaddress<cr>

/*loop each record where
/*customerID and orderID match passed arguments
/***loopstart***
OrderDetails.SKU <tab> Product.Productname <tab><tab> Orderdetails.Qty <tab> OrderDetails.Price<cr>
/***loopend***

Ordertotal.GrandTotal
--------------------------------------

Any help greatly appreciated.
THX,
Charles

View 2 Replies View Related

Building A Database

Aug 23, 2004

I am working with SQL server 2000. The database is installed in my machine. Now I have got the ".ldf" and ".mdf" file pertaining to a database from someother server.

Is it possible to build the database present in the above said files in my server.

NOTE : I dont have a direct access to the remote server from where the above said files were obtained (otherwise I think the DTS utility would have come in handy).

View 4 Replies View Related

Help With Building Query

Feb 14, 2007

Hello,

This will probably be trivial and basic for most, but I'm having a hard time trying to figure out the best way to do a SELECT statement. First, let me explain what I have:

Two tables:

Table 1:
Orders
Some of the fields:
ID
PropID
WorkOrderNum
OrderDesc
DateCompleted



Table 2:
OrderDetail
ID
OrderID
TenantName



As you probably have realized, the OrderID in my 'OrderDetail' table corresponds to the ID field in my 'Orders' table. The 'Orders' table contains the order header information, while the OrderDetail contains line items for that order - 1 line item per record.


Here is my SQL statement to retrieve an order when searching by the 'Order Description' (Orders.OrderDesc):


SELECT PropertyLocations.PropertyLocation, Orders.ID, Orders.PropID, Orders.WorkOrderNum, Orders.OrderDesc, Orders.DateCompleted FROM PropertyLocations, ORDERS WHERE PropertyLocations.ID = Orders.PropID AND OrderDesc LIKE '%lds%'


Ok, so now for the 'big' question/problem: I also need to be able to search the 'Tenant Name' field from the 'OrderDetail' table. So what is the best/most efficient way of doing that? The other stipulation about that is that there can be (and usually is) several records/line items (in the OrderDetail table, of course) that contains the same (or similar) data, but I don't want duplicates. And when I say duplicates, all I care about is retrieving a few fields (as you can see from my SQL statement) from the 'Orders' table. Another way to describe what I want is that I want all unique orders that have a 'TenantName' in the 'OrderDetail' table that matches the search criteria. My brain just isn't wanting to figure this out right now, so I was hoping someone could help me out.

thanks.

View 9 Replies View Related

Recommendations For Building An App.

Jun 19, 2008

I have a SQL 2005 database containing the location of graphics files. I want to start learning how to write a C# application that will get a path from the DB and display the file. Any recommendations on sites where I can start learning how to do this?

Thanks

View 1 Replies View Related

Building A Database

Jun 18, 2007

Hi I've been asked to design a samll database in access with 5 tables and 3 querys also a form, and reports.

I'am not to sure on what to charge the person would any1 have a idea on what a small to medium database would be cost to build.

Thanks

View 2 Replies View Related

Report Building

May 5, 2006

Can you build reports using SQL Express w/o SQL 2005. If so how, the online books are not making this very clear.

View 1 Replies View Related

Need Help Building/reading C# SQL Array

Jul 27, 2007

I'm stuck and uinder a bit of a time crunch. I have 5 fields I want to get out of a sql database using a function that I'm writing. I figure it sounds like an array. basically I want to make an array, and fill it up with the results of a sql select, then read the array. This is what I have so far.....         String TempHRAcctCode, TempJobDescription, TempHourlyRate, TempEmplID;        Array TempArray;        TempJobDescription = DDDept.SelectedItem.Text; (to get KeY Value)        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MYCONN"].ToString());        connection.Open();        SqlCommand command = new SqlCommand("Select HRAcctCode, HourlyRate , EmplID, ...  FROM TimeMyProfile  WHERE JobDescription = " + TempJobDescription + " ", connection);        SqlDataReader TempDataReader = command.ExecuteReader;        while TempDataReader.Read            (            ... OK I GIVE UP!  Thanks in advance        

View 2 Replies View Related

Problems Building Sql Statement

Nov 15, 2007

Hello,
I'm having problems building an sql stament that joins a few tables. I can seem to get my head around the structure!
I have to try and link up four different tables to try and get my result.
Here are the 4 table structures...
Web_Users----------------User_IDName
Tags_Table-----------------Tags_IDUser_IDGroup_IDTitle
Created_Groups-----------------------Group_IDGroup_Name
Tags_To_Groups------------------------Group_Link_IDGroup_IDTag_ID 
Basically, this database, has four tables; One table (Web_Users) that contains a users name, and assigns a unique ID (User_ID), another table that stores a users tags they have created, and also links it to a group_ID. The created_groups table, contains group names and assigns a unique id also. And the last table, Tags_To_Groups, links tags to groups.
So this is what I'm trying to do...
I'm trying to get the Group_name field from Created_Groups table, of a tag , that belongs to a certain user. If sounds easy when I say it like that, but I've been inner joining tables all night and failing every time.
 Does this make sense? Can anyone help?
Thank you

View 3 Replies View Related

A Query Building Question

Jan 30, 2006

Hi there,
i have a query building question and was hoping that one of you would know the answer.
Here is what i need to do :(i am using asp.net and ado.net)
I have 1 table where I store thedata,  where 5 criteria determine a unique row in this table. Now, this has recently changed as the start date was added. So there potentially can be more than one entry in the table with same 5 criteria, but different start date.
I need to retrieve the row with the latest start date (currently active). The problem arises when the users enter less than 5 criteria. In this case the results may not possess same 5 criteria. Say the user searches based on 2 criteria. Then all the rows possessing these 2 ctieria will be returned, but other 3 criteria might differ with the results set.
But, i only need the latest start date row for each row. So for example, if i searched on 2 criteria, i got back 4 rows, 2 of which possess the same 5 criteria. But between these 2 i only need to display ONE row to the user - the one with the latest date.
How do i build a query? say the table name is tbl, and criteria 1 to 5 fields are  called c1 ... c5, and start date field is called start_date.
thanks in advance
 

View 1 Replies View Related

Cannot Open Database While Building

Mar 21, 2006

Hi Everyone,I'm facing this problem now.Cannot open database "C:myDB" requested by the login. The login failed.Login failed for user 'myLaptopASPNET'.May i ask how can i resolve?Please feel free to let me know the information you need.Thank You!

View 3 Replies View Related

Building A Table From SQL Query

Apr 21, 2006

I am hoping someone can point me in the right direction with this.I have query that returns all the colums in a row (SELECT * FROM table WHERE value = 'value') and I need to build a table with this data.  Some of the columns may not have values in them, and so I dont want to build a table row for it.  I also need to use the column name as the table header.  As an example:==============================Column Name    || Column Value-----------------||-----------------Column Name    || Column Value
-----------------||-----------------
I hope I have explained myself properly.  Any help would be greatly appreciated.

View 4 Replies View Related

Sql 7 Enterprise And Node Re-building

Jul 18, 2001

Hi all,

I have a question about re-creating the sql portion on either node a or b in a clustered situation. Is it possible to do this without affecting the working node and database ? or is the best solution to make a ghosted image of the node after install is complete and if the node fails just get to a point on the affected node where you can copy the image back?

Thanks for any feedback.

P

View 1 Replies View Related

Building Relationships Between Multiple DB&#39;s

Jan 20, 2000

During the set-up of my DB's and their tables, I was unable to setup a relationship between a table in one Database and another table in my other Database ( using the diagram ). Maybe my datastructure of multiple databases is not correct, or is their an option to set relations between multiple databases ?

PS in the future I planned to have some other databases on different servers.

View 1 Replies View Related

Building Search String ?

Sep 20, 2000

The procedure below is for a 3 field wildcard search window.

It works fine if you enter a value such as cheese in @product_name.
If you enter cheese in @product_name1 or @product_name2 it returns nothing.

The string builds OK with values inserted where they should be, obviously there is a problem in the looping back of variable.

I've been looking at this so long I'm sure that the obvious solution is staring me in the face, but I just can't see it.

Any help would be appreciated.


Alter PROCEDURE usp_RobSearchTest
(
@product_name nVarChar(100),
@product_name1 nVarChar(100),
@product_name2 nVarChar(100),
@country_id nchar (3),
@language_id nchar (2)
)
AS




DECLARE @Variable nVarChar (100)

DECLARE @SQLString NVARCHAR(1000)

DECLARE @ParmDefinition NVARCHAR(1000)





/* Build the SQL string once. */

SET @SQLString =

N'SELECT product_name,unit_price,item_id,refund_price
FROM PRODUCT_LISTING
WHERE product_name LIKE ''%' + @Product_name + '%''
ORDER BY product_name'


/* Specify the parameter format once. */

SET @ParmDefinition = N'@product_name nVarChar (100)'

/* Execute the string with the first parameter value. */

SET @Variable = @product_name

EXECUTE sp_executesql @SQLString, @ParmDefinition,

@product_name = @Variable


/* IT WORKS UP TO THIS POINT */
/* Execute the same string with the second parameter value. */

SET @Variable = @product_name1

EXECUTE sp_executesql @SQLString, @ParmDefinition,

@product_name1 = @Variable

/* Execute the same string with the third parameter value. */

SET @Variable = @product_name2

EXECUTE sp_executesql @SQLString, @ParmDefinition,

@product_name2 = @Variable

View 1 Replies View Related

Building Indexes - How Long?

Jul 21, 1999

How long should it take, roughly, to build an index on a single field in a 12gb table?

View 1 Replies View Related

Building A Mailing List

May 23, 2006

Hi folks,

I'm building a DTS package which needs to mail a list of users nightly

The mailing list needs to be dynamic so I'm using the dynamic properties tab to populate the To, From etc. fields in an SMTP DTS task.

I need to construct a script which will run within the DTS package and build a mailing list file from a table of users in the connected db. The Dynamic properties task will then pull from this data file when populating the 'To' field.

The basic select statement is simple (e.g. SELECT email FROM employees WHERE role = 'mgr') however I need the output to be a single line of email addresses separated by commas (e.g. Email1,Email2,Email3....etc).

I'm a bit unsure on how to go about doing / writing this.

Can anyone help?

Thanks,

Dave

View 7 Replies View Related

Building Text Files

Jan 12, 2004

Ok, I have an sp that'll build an SAP feed based on parameter input (params control which type of file I want to create). I want to build 9 files in total.

I have a table set up with my parameters and output file names.

Question 1: Process from DTS
I have a DTS package which will build a file based on params and filename from table, pulled with a Dynamic Properties task. How can I iterate through my table of parmas to create the muliple files?

Question 2: Process from a stored proc
I have a stored proc, from which the interation through values is simple. How can I create and export to the text files from the stored proc? I think I may be having a mental fart on this one. I could create a text linked server dynamically, but I have not played with them much, How to I write to one (create table etc).

PS: The file data cannot include cilumn headings

TIA -
bpd

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved