Variable Parameters - Which Approach.

Jul 20, 2005

ASP.NET / VB.NET
SQL Server 7.0

Our client has insisted that we change our established practice of
building SQL in-line and move it all to SPROCs. Not a problem for 80%
of the app. However, we have a number of Search/Filter forms that
contain a number of controls to allow more or less focused search
criteria to be built up.

I have a class that does this quite nicely, examining all controls for
valid input and, if found, concatenated onto the end of what becomes a
"WHERE" clause. Once all is done the "WHERE" clause is appended to a
SQL Statement and passed to an ExecuteReader function. Only at
runtime is it known how many, and which, controls will be used in the
filter.

I can think of two methods of approaching this variable parameter list
which will be required if moving to SPROCs.

METHOD 1.
Create a SPROC where ALL the possible parameters are used. For
example:

CREATE PROC stpSearchContactsUsingContactRef
@ContactRef varchar(50),
@Status varchar(50),
@IgnoreDate int,
@Date1 smalldatetime,
@Date2 smalldatetime
AS

SELECT
tblContactSources.*
FROM
tblContacts
WHERE
(tblContacts.fldContactID LIKE @ContactRef) AND
(tblStatuses.fldStatus LIKE @Status) AND
((tblContacts.fldDateCreated >= @Date1) AND
(tblContacts.fldDateCreated <= @Date2) OR @IgnoreDate = 0)
GO

If either of the parameters @ContactRef and @Status is empty, the code
that retrieves the filter values passes in the value '%', otherwise it
will pass in the user's choice. If the user wants not to search on the
date range, then @Date1 and @Date2 are passed in with '' and
@IgnoreDate is set to 0.

METHOD 2.
Create a SPROC which consists of SQL body as a string, with the
"WHERE" clause passed in as a string parameter, and both EXEC'd -

CREATE PROCEDURE stpTSRGetFilteredTSR
@WhereClause as varchar(3999)

AS

DECLARE @Body as varchar(3999)
DECLARE @OrderBy as varchar(3999)

SET @Body = 'SET CONCAT_NULL_YIELDS_NULL OFF
SELECT TOP 100 PERCENT
tblTSRs.fldTSRID, tblTSRs.fldFaultDescription,
tblTSRs.fldDateEntered, tblTSRPriorities.fldTSRPriority,
tblTSRs.fldTSRPriorityID, tblVehicles.fldRegistrationNumber,
tblVehicles.fldVIN, tblTSRStatuses.fldTSRStatus,
tblTSRs.fldTSRStatusID, tblTSRs.fldDealerID, tblTSRs.fldEmergency,
tblCustomers.fldFirstName + '' '' + tblCustomers.fldSurname AS
fldCustomerName
FROM
tblContactReasons
INNER JOIN tblContacts ON tblContactReasons.fldContactID =
tblContacts.fldContactID
INNER JOIN tblCustomers ON tblContactReasons.fldRegardingID =
tblCustomers.fldCustomerID
INNER JOIN tblVehicles ON tblContactReasons.fldVehicleID =
tblVehicles.fldVehicleID
RIGHT OUTER JOIN tblTSRs WITH (NOLOCK)
LEFT OUTER JOIN tblTSRStatuses ON tblTSRs.fldTSRStatusID =
tblTSRStatuses.fldTSRStatusID
LEFT OUTER JOIN tblTSRPriorities ON tblTSRs.fldTSRPriorityID =
tblTSRPriorities.fldTSRPriorityID ON tblContacts.fldContactID =
tblTSRs.fldContactID
WHERE (GETDATE() <= DATEADD(week, 2, tblTSRs.fldDateEntered))'

SET @OrderBy = 'ORDER BY tblTSRs.fldDateEntered'

SET @Body = @Body + @WhereClause + @OrderBy

EXEC (@Body)
GO

In this example, the @WhereClause parameter might typically be:
' AND (fldDealerID = 9) AND (fldTSRStatusID = 1) '

My question is, is there anything to recommend one method over the
other?

TIA

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk

View 3 Replies


ADVERTISEMENT

Parameters Approach To Fill Report Header With Source Data Doesn't Work

Jan 19, 2007

It's well known issue, that one can't use any dataset fields in a
report header/footer directly. One of the approach is to create
query-based parameter that basically equals
=First(Fields!@FieldName@.Value, "@DataSetName@") and use that
parameter value instead. But it doesn't work in my case!



My report displays some entity description and is parametrized with
EntityID param. Its header contains entity name that, according to the
approach, is queried from the data source through the EntityName
report parameter. There's important issue: the report is displayed in
ReportViewer control, that is embedded into my application and entity
ID parameter isn't ser by user in ReportViewer parameters area. Its
default value is changed by the application with SetReportParameters()
web method every time a user wants to view the report according to the
entity the user is exploring in the application. But after the report
has been rendered, its header always contains not actual (outdated)
entity name. Nevertheless, the report body contains actual data
(including entity name). If I alter entity ID parameter in ReportViewer
or in web-based Report Manager and refresh report, header displays
correct entity name.



What's wrong in the workflow described?

View 3 Replies View Related

SP With Variable Number Filled Of Parameters

Jun 14, 2007

I have a SP search_post (e.g)

@id int,
@author varchar(40),
@keyword varchar(40),


select * from
posts
where
id = @id and author =@author and message like @keyword


in my case a user can choose to search by one or more of this elements.

what will be the best approach to write a statement that will account for the posibility of the user leaving some "parameters" empty, while also allowing for the posibility that all parameters could be filled


one approach I have thought out is this

if (@id IS NOT null)
select * from
posts where id = @id


if (@author IS NOT null)
select * from
posts where author= @author



if (@keyword IS NOT null)
select * from
posts where keyword = (@keyword



but this does not really take care of the posibility that all of them or some of them will be null while others will not

any suggestions ?

View 5 Replies View Related

Efficient Queries With Variable #'s Of Parameters

Dec 13, 2006

I want to create a web page where a user can select from 1-100 fields to include in output, and then query a table to only return the fields the user has selected.

I do not want to construct a dynamic SQL SELECT statement. I would rather use a stored procedure, but am not certain how to only return the fields that the user selected.



View 1 Replies View Related

Updating/getting Values From Datagrid In C# With Variable Parameters

Oct 24, 2006

HiI am new to the world of aspx, .net and C#.In aspx .net 2.0. I am trying to work out how to get a datagrid to perform an update. Using Visual Developer I have successfully added the control and specifed a select statement to return data via my SQLData Source. This works fine. However having specifed the control as editable I would like to perform an update through the datagrid and SQLDatasource. I see in the properties for the SQLDatasource object I can specify my update statement.However I do not understand how to get that update statement to have variable values and how newly entered values from the grid can be placed into these variables when the update takes place. Can someone please point me in the right direction? I have not found the MS doc very illuminating thus far and have not found any examples.Many ThanksT

View 1 Replies View Related

Passing '% Variable %' To SqlDataSource Through E.Command.Parameters

Feb 23, 2008

 Hello all,I'm writing a site with one page that uses the session variable (User ID) to pick one user ID out of a comma separated list in the field Faculty. The default parameterized query designed in the SqlDataSource wizard only returns lines that contain an exact match:SELECT * FROM tStudents WHERE ([faculty] = @faculty) The query: SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') works as I need when I hard code the query with a specific user ID into the SqlDataSource in the aspx page.  It will not work if I leave the @faculty parameter in it:SELECT * FROM tStudents WHERE ([faculty] LIKE '%@faculty%') e.Command.Parameters works to replace the @Faculty with a user ID, but again, adding the single quote and percentage sign either causes errors or returns no results.  I've tried several variations of:         string strEraiderID = "'%" + Session["eRaiderID"].ToString() + "%'";        e.Command.Parameters["@faculty"].Value = strEraiderID;no results are returned, not even the lines returned with the default select query.How do generate the equivalent of SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') into the SqlDataSource? Thanks much! 

View 3 Replies View Related

Setting Variable Parameters In A SSRS Subscription

Nov 7, 2007

I would like to set up a subscription that has two date parameters, I would like the end_date to be today and the start_date to be (today - 1 Month). The interface does not seem to support expressions?

I saw some documentation that said to use defaults in the report but that does not help because I may want multiple subscriptions with different params like 1 person may want (today - 2 months) as the start date ...

Any help would be appreciated

View 9 Replies View Related

Stored Procs With Variable Number Of Parameters

Oct 26, 2006

I have received a change request for a project i am working on which im unsure if possible or not.

at the minute i have a very simple sp that simply selects data from a table by passing in one parameter

CREATE PROCEDURE PHAR_SelectGrade

@int_ID int

AS

 SELECT GradeID as ID, Grade as Description, RequiresText, SendEmail, Timestamp
 FROM tbl8Grade
 WHERE Obsolete=0
AND GradeID = @int_ID
ORDER BY Grade

the user now wants the option to select more than one grade type (there are 100's of different grades)

so they might decide they want to see details for 2 grades, 22 grades etc. these would be selected and stored in an array (via an asp.net project) and then the stored procedure is called from within a web service

my question is how would i pass this array into the stored procedure??

i am assuming i would need to do something as follows for sp syntax, but im stumped on how i pass my array of values into the sp from the webservice and then for the sp to read the array in SQL??

CREATE PROCEDURE PHAR_SelectGrade

@myArray <what datatype?>

AS

 SELECT GradeID as ID, Grade as Description, RequiresText, SendEmail, Timestamp
 FROM tbl8Grade
 WHERE Obsolete=0
AND GradeID IN (@myArray)
ORDER BY Grade


any ideas are greatly appreciated. or maybe its just not possible?!?

Cheers,
Craig

View 3 Replies View Related

Stored Procedure - Variable Number Of Parameters For Search

Dec 4, 2003

Hi,
I have a repeater control which I populate with search results from SQL Server.

But I can't figure out how to cope with users who submit multiple search items and still use my stored procedure. Is this possible or do you have to build the query with a StringBuilder and execute it manually?

I'm using a stored procedure with parameters:

input parameters <-- PageSize & CurrentPage
output parameter --> TotalRecords

Am using a temporary table to store all records before Select-ing those required for the particular page.

If I compose the query manually then I can't figure out how to get TotalRecords back as a return parameter. Would appreciate help on this one.

Am hoping that stored procedures can cope with an unknown number of parameters.

View 3 Replies View Related

Passing In Variable Number Of Parameters To A Stored Procedure

Jul 9, 2006

I am fairly new to MSSQL. Looking for a answer to a simple question.

I have a application which passes in lot of stuff from the UI into a stored procedure that has to be inserted into a MSSQL 2005 database. All the information that is passed will be spilt into 4 inserts hitting 4 seperate tables. All 4 inserts will be part of a stored procedure that have to be in one TRANSACTION. All but one insert are straight forward.

The structure of this table is something like

PKID
customerID
email address
.....

customerID is not unique and can have n email addresses passed in. Each entry into this table when inserted into, will be passed n addresses (The number of email addresses passed is controlled by the user. It can be from 1..n). Constructing dynamic SQL is not an option. The SP to insert all the data is already in place. Typically I would just create the SP with IN parameters that I will use to insert into tables. In this case I can't do that since the number of email addresses passed is dynamic. My question is what's the best way to design this SP, where n email addresses are passed and each of them will have to be passed into a seperate insert statement? I can think of two ways to this...

Is there a way to create a variable length array as a IN parameter to capture the n email addresses coming in and use them to construct multiple insert statements?

Is it possible to get all the n email addresses as a comma seperated string? I know this is possible, but I am not sure how to parse this string and capture the n email addresses into variables before I construct them into insert statements.

Any other ways to do this? Thanks

View 7 Replies View Related

Forwarding Variable Number Of Parameters From VB.2005 To Sql Server 2005 Stored Procedure

Jan 15, 2008

I have a problem regarding forwarding 'n number of parameters' from Visual Studio 2005 using VB to SQL-Server 2005 stored procedure.I have to save N number of rows in my stored procedure as a transaction. If all rows are not saved successfully, I have to roll-back else update some other table also after that. I am unable to handle - How to send variable number of parameters from Visual Stduio to Sql - Server ? My requirement is to use the SQL-Stored Procedure to store all the rows in the base table and related tables and then update one another table based on the updations done. Please Help .....

View 1 Replies View Related

Best Approach With DTS

Mar 30, 2004

Let me see if I can explain this.

I have the need to pull data from multiple tables from a DB2 system via ODBC and update or insert as needed into tables in a SQL200 DB.

Step 1.
The data from the initial parent table will need to be limited to being a set number of days old, which I have in place and working.

Step 2
The next tables data needs to be limited from the data retrieved in step 1 (I’d like to use the paprent table retrieved in step 1, that is in SQL now, rather than doing it on the DB2 side.

Step 3
The returned rows here, need to be limited to key values returned from step 2

Additional steps apply, but nearly all will be limited to the results of parent tables from the prior step.

What is the best approach to this? I really want to pull table A to SQL, and limit the next child set from Table A, that was pulled to SQL in the prior step.

I also need to do updates rather than dropping and creating the needed tables each time. Insert if no key exists, etc .etc.


What is the best approach?

View 2 Replies View Related

Best Way To Approach This

Mar 20, 2006

I've been working on this project, and had it working in MySQL, but it was badly done and couldn't last more than a few hours without growing so large that everything slowed way down. I don't expect anyone to tell me exactly what to do, just please provide an outline of what the best way to approach this in SQL Server 2005 is.

To simplify it, I have one table "Items" and another table "ItemPrices". Items has an id and a name. Each row in ItemPrices has an id for the item, a price and two datestamps (added, last updated).

On average, there's about 15,000 active items, 50% of them have new prices every couple minutes, so I'm looking at what seems like a ton of data being constantly imported. There's probably a good way to do this but I only know the bad way :)

So.. what I want to be able to do is have maybe a stored procedure (?) that takes the item name and price as parameters. (In MySQL I was using "INSERT... ON DUPLICATE KEY UPDATE")
A. If it's a new item name, it will add a row to the Items table and a row to ItemPrices
B. If it's an existing item with the same price as the current price (the most recent price for that item in ItemPrices) it will update the "last updated" date field
C. If it's a new price it will insert a row into ItemPrices for that item

Also, I want historical pricing data, but if I ever release this, 95% of the users will just be looking at current prices. I need the current prices to be very fast to query, in my MySQL version I was using something like this: "SELECT... join on lastupdated=(SELECT Max(lastupdated) FROM ItemPrices ...", after I had 300k price updates querying a list of items took like 15 seconds.. there's got to be a better way? What should I do to make this faster?

Does this make any sense? Hopefully someone can lead me in the right direction. Thank you very much!

View 3 Replies View Related

Appropriate MDX Approach ???

May 24, 2008



Hello all.


I use MDX on a cube which provides data about animal population.


The cube contains the keyfigure "ANIMALS" that takes the number of animals.

The cube has a dimension "VERSION" which is used to identify the keyfigure
as a target or an actual value (possible values: "actual" and "target")
The cube has another dimension "ZONE" for the population zones.
Possible values for zones: "A", "B", "C" and "D".


Now I want to create an MDX statement, that gives me a result row like this:

Actual number of animals (as sum of all 4 zones) in column no. 1,
Target number of animals (as sum of all 4 zones) in column no. 2,
Achieved percentage (as actual number / target number * 100) in column no. 3.


Until here my statement works and it looks like this:


WITH MEMBER [VERSION].[achieved] AS '[VERSION].[actual] / [VERSION].[target] * 100'
SELECT {[VERSION].[actual], [VERSION].[target], [VERSION].[achieved]} on COLUMNS
FROM [$MYCUBE]
WHERE ([Measures].[ANIMALS])


It surely is possible that the achieved value for all zones together is equal to or greater than 100%,
while single zones might have an achieved values less than 100%.


In order to account on this, i would like column no. 4 to display one of these words:
"ok" if none of the single zones has an achieved value smaller than 100%,
"warning" if any of the single zones has an achieved value between 96 and 99%,
"alert" if any of the single zones has an achieved value smaller than 95%.


That means, i want e.g. the word "yellow" if the lowest achieved value
of the 4 zones is between 96 and 99. I want to have "red" if the lowest value
is smaller than 95.


I am quite new to MDX and I have struggled quite a long time with this.
I would be grateful for a hint on how i have to modify / enhance my MDX statement.


Regards. Peter.

View 1 Replies View Related

Best Approach

Sep 27, 2006

I have what I feel like is a simple package I am working to create. I am teaching myself SSIS as I go along.

Source server SQL 2000 database allows NULL values in columns.

Destination Server also SQL 2000 but the database required a value in each column.

So I do a basic source select what I want. I next need to read the values and determine if null then insert a space, do some column matching and insert them into the destination sever.

I believe I should use a Derived Column and an expression ISNULL to accomplish what I want.

Maybe there is a better way. Suggestion and comment appreciated.

Ryan


View 1 Replies View Related

Help With Using The Right Approach

May 18, 2006

Greetings my friends

I am attempting to solve the following problem using SSIS, actually I am attempting to convert a SQL Server 2000 DTS package in to a SSIS package.

The package does the following :

1) Retrieve the maximum Price_ID (PK) from a PRICE dimension table.

2) Populate a staging table with data coming from a source system where the PRICE_ID > (Price_ID from above)

3) Update the actual DIM table with the new data help in the staging table.

For this task I want to learn the use of the Lookup component which I think is appropriate.



My questions are as follows :



If I create a global variable to hold the maximum PRICE_ID (see point 1). How do I get to use the variable in the my Data Flow Data source?!



I am totally confused... I don't even know where to start with this.



Your help would be appreciated.



Thanks SQL friends.

View 6 Replies View Related

Best Approach

Jun 21, 2006

I've been banging my head for a while now, and it is sore! :-P

I'm a best practice/Microsoft approach type of person and want to make sure I do things correctly.

I have a database, kind of like a forum.



Obviously executing multiple queries in one "batch" (stored proc) would have an impact on the performance.



Now, I would like to give a more detailed/specific error back to the caller (either by aid of error code or whatever) with such situations like...

"EditReply"

Edit reply takes the threadID, replyID and userID.

Before actually commiting the changes, it needs to check:

1) does the user exist in the database? (during the editing of the reply, perhaps the user may have been deleted before running the stored proc, who knows)

2) does the thread exist?

3) does the reply exist?



if the conditions are met, only then will it go ahead and update the database. Now that is 3 queries, and 4 statements overall to make a change to a field/table.



Obviously if one of the commands returns false, in other words if say "does the thread exist" returns 0 (thread doesnt exist) it will return back to the caller an errorcode, which they will handle in their application. Thats all fine but the question is



Am I doing this correctly? (no) - how can I improve this? What do I need to think about?

Of course I would like to give a more detailed error back to the caller (aid of errorcode designed in the application overall) instead of just "no, databases not updated".



In this situation, am I wrongly assuming that the database designers use this type of approach?



Please help, I value your feedback and suggestions. I want to improve and think of the right lines of doing these things.

View 12 Replies View Related

SqlBulkInsert ?? Or Better Approach?

Aug 7, 2006

Hello,

I'm doing my best here, but need some help. I have a client that has a company list that they want searched by key word. This is exported from another program (in excel) that they want used and searched on their website.

Bad news, is each Keyword is listed with the company separately. So if a company has 5 different key words, they will be listed in the excel file 5 times.

The info I have is Name, Address, City, State, Phone, Keywords:

So example of excel is:Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Green
Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Furry
Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Large
Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Circular
Company B, 746 Sparrow Ave, Diffcity, Diffstate, 987-987-9876, Blue
Company B, 746 Sparrow Ave, Diffcity, Diffstate, 987-987-9876, Furry
Company B, 746 Sparrow Ave, Diffcity, Diffstate, 987-987-9876, Small

I am able to import this large (4.2 MB) file into a table called fctable

What i'm trying to do is write SQL scripts or queries that can insert into a Company Table and Keyword Table.

I'm trying to write this through asp.net 2.0 (so the excel file is uploaded) and have tried to write my inserts like

INSERT INTO [Company] ([Name], [address], [City], [State], [Phone]) VALUES (SELECT DISTINCT
Name, Address, City, State, Phone
FROM fctable )

But that doesn't seem to be working.

This is the only way my client can get the info to me, and it will be changed probably twice per month, so I'd hate to have to try to manipulate an excel file 24 times a year to import.

Any suggestions Appreciated

View 2 Replies View Related

SQL OPENXML: Best Approach

Feb 27, 2008

Hello everyone.
I am new to.Net and here is what I have to do.
 I needto update a SQL table with data coming from a XML file.  I have seen some Microsoft documentation on this (the nice SQL statement that updates and inserts in the same stored procedure) but I don'tknow what is the best approach for passing my XML file to the stored procedure.  The XML contains about 12 000 records, kind of phonebook info (name, email, phone).
 What would be the best approach to do this?  What objects should I use?
 Thanks a million,
Ben
 

View 2 Replies View Related

MS SQL Server 7.0 And Approach

Oct 18, 1999

Environment
NT Server 4.0 w/ SP4
SQL Server 7.0 w/ SP1
Win98 Client w/ Lotus Approach 9.5

I recently added SQL 7.0 to be a back end for my Approach front end. I transferred all the data from a dbase IV in approach to SQL. Most of the conversions worked ok. I have two big problems.

1) One particular repeat panel in Approach loses the children records of the master record. If I delete some of the records, more will appear. It's as if there is an imaginary limit of the number of records it can read in the repeat panel. I don't have this problem with any other records and children in repeat panels. I called Lotus and they don't have an answer. This is important because the children records need to be summed up so I can have a running total.

2) I original configured the clients to use the TCP/IP Netlib w/ the default port. I couldn't open enough databases so I changed to Multiprotocol. This allowed certain clients to open more databases, but others can't open additional databases. Also, after the change, the NT authentication login has had problems. I had to change to the SQL login to get all my clients back on line. Sometimes the same client can't open more than 10 databases while other times it will open 15. There is no consistent patten to when it can and can't open the additional databases.

If anyone knows how to fix either of these problems, I would greatly appreciate any advice. I'm getting tired of my boss yelling at me.

Thanks.

Keith
akumaboyz@aol.com

View 1 Replies View Related

Not Sure How To Approach This, If /then Select?

May 12, 2008

I have a select statement where I need to test two values that are returned and perform a different calculation if they return null.

Basically,
if TESTA is null and TESTB is not null
return TESTB

if TESTB is null and TESTA is not null
return TESTA

ELSE if both are not null
TestA + TestB / 2 is value is returned

is this possible to do in a select statement? thanks in advance.

See select statement below:

Select S.StudentDimKey,
(select ISNULL(R.Score, NULL) from CLT_StudentAssessmentRawFact R, CLT_LessonPlanDim L where L.LessonPlanKey = 1 and L.LessonPlanDimKey = R.LessonPlanDimKey and StudentDimKey = S.StudentDimKey) as TESTA,
(select ISNULL(R.Score, NULL) from CLT_StudentAssessmentRawFact R, CLT_LessonPlanDim L where L.LessonPlanKey = 2 and L.LessonPlanDimKey = R.LessonPlanDimKey and StudentDimKey = S.StudentDimKey) as TESTB,
from CLT_StudentPlacementFact P, CLT_StudentDim S, CLT_ClassHierarchyDim H, CLT_StudentClassFact C
where P.StudentDimKey = S.StudentDimKey
and H.ClassHierarchyDimKey = C.ClassHierarchyDimKey
and S.StudentDimKey = C.StudentDimKey
and S.StatusCode = 'A'
and S.CurrentRecord = 1
and S.SchoolID = 87577

View 2 Replies View Related

Can A Set Based Approach Help Me Here...

Feb 1, 2007

im practicing set based approaches... and what im trying to do is grab each value from a table , scramble it and put it back in the table... i dont want the solution to this as id rather figure it out myself for practice...

the thing im stuck at is i can do this with a cursor but i want to avoid cursors in future, how would i use a set based approach to get each value of a table and work with it?

View 4 Replies View Related

Set Approach Instead Of Cursor

Jul 20, 2005

Hi,I am trying a Set Approach instead of Using of Cursor (which works).I am attaching the SQL to create tables and the my Procedure, and apiece of code to execute the Procedure.I would like the Procedure ReplaceTags to work with 'a' the same aswith 'C'.Thanks in advance.Hareesh/*****************************//* Create Tables */IF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID =OBJECT_ID(N'GlobalTags') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)DROP TABLE GlobalTagsGOCREATE TABLE GlobalTags(Project VARCHAR(50) NULL,TagName VARCHAR(50) NULL,[Value] VARCHAR(50) NULL)GOIF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID =OBJECT_ID(N'ProductDetails') and OBJECTPROPERTY(id, N'IsUserTable') =1)DROP TABLE ProductDetailsGOCREATE TABLE ProductDetails(Project VARCHAR(50) NULL,KeyName VARCHAR(50) NULL,[Value] VARCHAR(50) NULL)GO/*********************************//* Populate Tables */TRUNCATE TABLE GlobalTagsINSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'FirstName', 'John')INSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'LastName', 'Doe')INSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'PhoneNo', '5248')INSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'ZIPCode', '55555')TRUNCATE TABLE ProductDetailsINSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'FirstName', '%FirstName%')INSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'LastName', '%LastName%')INSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'PhoneNo', '%PhoneNo%')INSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'ZIPCode', '%ZIPCode%')/****************************//* Procedure */IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ReplaceTags')DROP PROCEDURE ReplaceTagsGOCREATE PROCEDURE ReplaceTags(@aProjectName VARCHAR(50),@aProcessType CHAR(1))ASBEGINDECLARE @TagName VARCHAR(50)DECLARE @Value VARCHAR(50)IF @aProcessType = 'C'BEGINDECLARE REPLACE_CURSOR CURSOR FAST_FORWARD READ_ONLY FORSELECT TagName, Value FROM GlobalTagsWHERE Project = @aProjectNameOPEN REPLACE_CURSORFETCH NEXT FROM REPLACE_CURSOR INTO @TagName, @ValueWHILE (@@FETCH_STATUS = 0)BEGINUPDATE ProductDetailsSETValue =CASE WHEN CHARINDEX('%' + @TagName + '%', Value, 1) > 0THENREPLACE(Value, '%' + @TagName + '%', @Value)ELSEValueENDWHERE Project = @aProjectNameFETCH NEXT FROM REPLACE_CURSOR INTO @TagName, @ValueENDCLOSE REPLACE_CURSORDEALLOCATE REPLACE_CURSORENDELSEBEGINUPDATE ProductDetailsSETValue =CASE WHEN CHARINDEX('%' + GlobalTags.TagName + '%',ProductDetails.Value, 1) > 0 THENREPLACE(ProductDetails.Value, '%' +GlobalTags.TagName + '%', GlobalTags.Value)ELSEProductDetails.ValueENDFROM ProductDetails INNER JOIN GlobalTagsON (ProductDetails.Project = GlobalTags.Project)WHERE ProductDetails.Project = @aProjectNameENDEND/***********************************//* Run Procedure */EXECUTE ReplaceTags 'ProjectName', 'a'-- EXECUTE ReplaceTags 'ProjectName', 'C'SELECT * FROM GlobalTagsSELECT * FROM ProductDetails/* End*//***********************************/

View 6 Replies View Related

Should I Use A Trigger Or A Different Approach?

Apr 25, 2008



Lets say I have a dynamic table of 10 to 30 varchar(255) columns that I do not know the names of.



Each of these columns is updated with either an 'OK' or an error msg.



Here's the issue. I have a Status column (varchar(MAX)) which I want to be the concatenated sum of all the other columns. I'd like to do this via a trigger because the way I understand it, theres no way a trigger can skip over another update/trigger and write the wrong 'Status' value.



Example Row 1:

RandomColName1 = "1||Access Denied"

RandomColName2 = "0||OK"

RandomColName3 = "2||ID10T Error at Kbrd"

Status = "[RandomColName1] Access Denied | [RandomColName3] = "ID10T Error at Kbrd"



Example Row 2:

RandomColName1 = "0||OK"

RandomColName2 = "0||OK"

RandomColName3 = "0||OK"

Status = "0||OK"



The rules:

1. There is no chance of someone updating the same column at the same time.

2. There's a good chance that other columns in the same row will be updated at the same time.

3. Sometimes a column can be updated every 5 secs.

4. About 100 to 5000 Rows



I'm a SQL newb and this would be my first trigger to write (lol) but I feel if it could be done without causing a DEADLOCK then it should be done this way. Unless someone with more experience can shed some light



With up to 300 .net clients over fast and slow links, I don't want to xfer the whole 5000 row / 50 column table back to the app and have it weed it out, especially if the client only needs 100 of the rows. On the same token, I don't want to make an individual call back to the SQL server should the client need 4000 rows.
Thanks for the help!

View 9 Replies View Related

Mining Approach?

Jul 4, 2007

I have a scenario in mind and was wondering if anyone had any suggestions on an approach.



Lets say I have a dataset where I have captured various attributes about blade servers in a rack. I have internal temperature, fan speed, disk reads, cpu temperature and failure events. Each of these are continuous variables except for the failure event, which has only two states, 'true' or 'false' which indicates whether a failure occurred at that point in time.



The table looks like this:







MachineID
Timestamp
Temperature
FanSpeed
Reads
CPUTemp
Failure



At the time of failure, only the MachineID, Timestamp and Failure values will be populated in the table. The failures at this time are not categorized or discriminated from each other in any way although they will be in the future. We're looking to use a mining algorithm to determine which variable is the best predictor of failure, or combination of variables. What do you think is the right approach? How might this approach change once the failures do become categorized and differentiated?



Thanks,

Frank

View 4 Replies View Related

Configuration Approach

Aug 13, 2007

Background


I use four database connections strings.

I have about 30 packages that will use one or more of the connection stings.

I store the connection strings in XML configuration files.
I know that I can share configuration files across packages. Should I ?

Have one configuration file with all 4 connection strings? If I use this approach will I get errors in the packages that only use 1 of the connection strings OR

Create four separate configuration files (CnnString1.dtsconfig, CnnString2.dtsconfig, CnnString3.dtsconfig, CnnString4.dtsconfig) and use the appropriate ones for each package

Take another approach

View 5 Replies View Related

Question On An ETL Approach

May 23, 2008

Let me use a simplied example for what I'm trying to do.

Say, I have the following source tables.

T_EmpDept

Emp_Name, Dept_Name
John , IT
Mary , IT
Ted , HR

T_Employee

EmpID, Emp_Name
1 , John
2 , Mary
3 , Ted

T_Dept

DeptID, Dept_Name
1 , IT
2 , HR

Now, I wan to populate a target table that looks like

T_Target

EmpID, DeptID
1 , 1
2 , 1
3 , 2

So, it's basically a lookup by name and translated to the appropriate keys.

The way I've done this before, is I do one lookup at a time in serial (one data stream) and get the keys I need. But I want to do them in parallel (split the data stream in two), which I believe involves a Multicast Task and some sort of a Merge Task. I used to shy away from the parallel lookup because I never really understood how to bring the two data streams back together.

So, the question I have is this. Are Multicast and Merge task the right tasks to use for this? I don't want to go researching something that may not be appropriate.

Lastly, if someone has a link that can lay this out for me, I would appreciate it.




View 7 Replies View Related

Best Approach For A Solution

Oct 9, 2007



I don't have much background with SSIS or SQLServer or development for that matter. I was thrust in to this and I apologize if my questions are not up to snuff in any way.

I have built an SSIS package based on the import/export wizard and have customized it by adding a For Each Loop container for processing multiple source data files and it works great so far but I need to add some advanced functionality to make it more flexible. I'm having some problems with the best way to enhance the solution and I'm getting frustrated with variables and expressions, which is what I think I need to use. Hopefull what I need is something that's doable.

The package processes mutliple source files using the For Each Loop. The data is stored in a destination table that is dropped and recreated each time. I've also added a couple of CREATE INDEX statements to the source SQL.

I need to make the SQL DROP, CREATE TABLE and INDEX statements dynamic based on part of the filename string. I'm capturing the filename in the FOR EACH container using Variable Mapping. What I need to do is parse out part of the string from the filename and use it in the SQL statements. An example would be CREATE TABLE XXX_[stringvar] where [string] comes from the variable mapping done in the For Each loop.

My thinking was to setup a new variable within the scope of the SSIS package and enable Evaluate as Expression and then build an expression for the varible where I parse out the string from the filename variable that already exists. So if the filename was filename.filetype and I needed the last 4 characters from the filename the string value would be whatever characters were in 'name' each time. But there isn't an expression builder editor built in to the variable properties expression element, so I'm not clear that I can actually create a variable in SSIS and then have it's value be set using an expression. It seems to me that if this was doable, then the expression builder I've seen elsewhere in SSIS would be visable.

Then I was hoping I could edit the SQL behind the DROP and CREATE statements where I've hard coded the table name and insert the variable right in the SQL. My SQL isn't that strong and I don't know how to work with variables but I was thinking the SQL would look like CREATE TABLE XXX_@[stringvar].... I believe another approach would be to setup another string variable for the entire SQL statement and build the statement string dynamically. But I don't know if this is necessary or better.

Anyway, I hope someone can help and that my original post is clear enough.

Thanks

View 4 Replies View Related

What's The Best Way To Approach This Situation?

Jul 12, 2007

Hello everyone,



I'm creating a database for a new application and I'm currently facing a design problem, regarding a business requierment for the membership module.



The Membership Module of the application has several business requierments, specified by the client. One of them is the ability to add and remove details about their members. So far, I've created a schema, named Person, which will contain a number of tables responsible for everything related with the membership, as an individual.



To help you guys understand the design I'm trying to implement, I'll post the fields of two of the tables that belong to the Person schema, as follows:



Person.Base

Id (uniqueidentifier)

UniqueIdTypeId (uniqueidentifier)

UniqueId (uniqueidentifier)

Password (char(88))

PasswordSalt (char(10))

PasswordRecoveryQuestion (nvarchar(256)) [NULLABLE]

PasswordRecoveryAnswer (char(88)) [NULLABLE]

CreationDate (datetime)

AuthenticationWindowStartDate (datetime)

AuthenticationWindowAttemptCount (tinyint)

IsActive (bit)

IsBanned (bit)

IsLocked (bit)

Status (bit)



Person.Emails

PersonId (uniqueidentifier)

EmailAddress (nvarchar(256))

CreationDate (datetime)

ValidationCode (char(10))

ValidationDate (datetime) [NULLABLE]

IsValid (bit)

IsPrimary (bit)

IsRollbackTarget (bit)

Status (bit)



So far so good. This design works great to preserve the data integrety. Nonetheless, this is where the problems start. Now, imagin you need to let someone from that company add an item to the user (through the application). Let's say we want to allow the company application manager to add an item to the person called "PreviousEmployer". Such item would then be used for statics, thus would probably need to be indexed.



In order to meet this business requierment I would create some addicional tables. Let's get started:



Person.CustomFields

Id (uniqueidentifier)

Name (nvarchar(50))

Description (nvarchar(3000)) [NULLABLE]

Status (bit)



Person.CustomField_Value

FieldId (uniqueidentifier)

Value (nvarchar(450))



This could work just fine if both are indexed (that's why the nvarchar size is set to 450). But I'm guessing this is far from the optimal solution for many reasons, one of them being the efficiency of the index if the company decides to go and use this for a flag (true or false [bit]). Another "solution" breaking scenario would be if the company wants to add the CV of the person, situation in which we were unlikely to be able to add a file in this datafield.



How would you guys approach this issue? The bottom line is that the client needs to be able to add pretty mcuh any type of custom field and perform searches againts it. So, besides being a dynamic solution it needs to be efficient.



Best regards and thanks in advance.

View 11 Replies View Related

Need Advice On Approach

Mar 8, 2007

I am new to DTS/SSIS and would like some input on an approach to solve a problem.

I have a solution using SQL Server 2005 and another legacy solution running on Access. Status records are written to a table in SQL Server and as they are written, I need to write a record to a table in Access. This needs to be as real-time as possible.

I thought about writting a managed stored procedure in C# so I could also access MS Access, but someone pointed me to DTS.

Records are constantly written to the status table and need to remain in there even after they are processed.

Can you recommend an approach or an article to read?

Thanks,


Steve

View 1 Replies View Related

How To Approach Complex SQL Query

Aug 1, 2007

Hi there! I'm looking for advice/suggestions on how to approach a query that's going to be much more complex than I have previously had to deal with.
I have a web form where users can select from a number of possible search parameters (say, City, State, Zip Code, etc...) and pull a list of users from this database, and can select the specific data fields they want displayed as well. The complicated part is that the possible search parameters (and data to display) are spread out over several tables.
 How should I go about tackling this little monster? If it's any help, I am using Visual Web Developer 2005 Express Edition and Microsoft ASP.NET Web Matrix to create this form.
Thanks a million,
Kaiti

View 2 Replies View Related

Update Trigger Best Approach

Jun 1, 2004

I need to create an update trigger which will have from 3-6 fields which can be updated in a master table (it could be different with each record, but it will always be these fields). Based upon that I will need to update corresponding tables. Isn't there a limit based upon the location in the table how you can do this. Is the best way to handle this with a bunch of if's?

View 1 Replies View Related

Best Approach Wher In Or JOIN

Dec 15, 2004

Hi,

I have 2 sets
Set1 has few UNIQUE items say workitem Ids 2,3,4

Set2 has multiple items say workitems Ids is 1,2,2,4,3,5,4,3,6,7,8

I need to look for Set1 in Set2 so i get 2,3,4 etc...

which is the best way

Set2 Left join Set1

OR

Select item from Set2 where item in (Set1)

View 3 Replies View Related







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