Showing posts with label point. Show all posts
Showing posts with label point. Show all posts

Friday, March 30, 2012

Multi Value Parameters

I have an issue using a Muiti Value Parameter. Upto a point it works
quite well.
The parameter is based on a field within the report & so when I preview
I get a list of values, and can select all, or some records. Thats the
bit that works.
However when I run the report it returns data for for 1 value only. I
have made sure that the filter on my report uses 'in' instead of '='.
One thing I would rater do thatn use the report filter is pass the
parameter directly to my SQL statement, does anyone know how this can
be done?
Thanks
PaddySo you're using a filter on the dataset (retrieve all rows first). This is
not very efficient, especially if you're dealing with tables with millions
of rows...
To do it on the data source side:
If your data source is SQL Server 2005, you can simply write your TSQL as
"...and myTable.myField IN (@.myParameter)"
If your data source is SQL Server 2000 or something else you could do either
of the following:
stored proc, pass the parameter to the stored proc as
=join(Parameters!myParameter.Value, ",")
Then write some code that splits your values out by "," and writes them to
an in-memory join table. Typically in the past, we've used a UDF to return
a table as well.
For a "straight query" (IOW TSQL, PLSQL, etc), as long as the data source
supports the IN clause, you could write dynamic SQL in the form:
="select ..... where myTable.myValue IN (" &
join(Parameters!myParameter.Value, ",") & ")"
If you go the dynamic sql path, write the query out first normally so you
don't have to fill in the field list, then change it to dynamic.
Clear as mud?
-Tim
"Paddy" <paddymullaney@.btopenworld.com> wrote in message
news:1152180850.976447.110760@.75g2000cwc.googlegroups.com...
>I have an issue using a Muiti Value Parameter. Upto a point it works
> quite well.
> The parameter is based on a field within the report & so when I preview
> I get a list of values, and can select all, or some records. Thats the
> bit that works.
> However when I run the report it returns data for for 1 value only. I
> have made sure that the filter on my report uses 'in' instead of '='.
> One thing I would rater do thatn use the report filter is pass the
> parameter directly to my SQL statement, does anyone know how this can
> be done?
> Thanks
> Paddy
>

Friday, March 23, 2012

Mulit table insert

Can some one point me in the right direction on this. I am trying to insert data into two different table. The problem is, even though table 2 had a "not null" on it's primary, the insert command still allow it to be null.

Here is what I am trying to do. When I click the submit button on my web app, it should send this information in for to table 2. The procedure should then pull the id2 and and enter it into the table as FK to table 1.

Like I said before, the id2 doesn't seem to pass any data because the procedure is passing a null, even thout a set the pk value to not null.


DECLARE @.identHolder int
DECLARE @.ID2 int

BEGIN TRANSACTION
IF NOT EXISTS (SELECT ID2 FROM [tbl2] WHERE ID1 = @.ID2)
BEGIN
(SELECT 2ID FROM [tbl2] WHERE ID1 = @.ID1) SET @.identHolder = @.@.Identity

END
ELSE
BEGIN
INSERT INTO [t2] ([fName], [lName], [shift], [userName], [emailAdd])
VALUES ( @.fName, @.lName, @.shift, @.userName, @.emailAdd) SET @.identHolder = @.@.Identity

END
COMMIT

SET @.ID2 = (@.@.Identity)
INSERT INTO [tbl1]([ID1], [ID2], [event], [removed])
VALUES (@.ID1, @.ID2, @.event, @.removed)I suggest you go back to old school debugging.
Stick a handful of

PRINT @.ID2
--Actually, you'll probably need:
PRINT Convert(varchar, ID2)

And watch the value.
Should the value perhaps be before the COMMIT?|||I figured it out. The "IF Not Exist" needed to be "If exist". I was telling the DB to check for a record but instead of creating the record if not exist, I was selecting it. Once I change that it work. I think I had to fix a datatype too.

Thank you.|||You should also put some error handling after the INSERT to rollback (or whatever) in case of an error (constraint, FK, unique index etc). Use the @.@.ERROR function in SQL Server 2000 and TRY...CATCH in SQL Server 2005.

Many people seems to forget about TSQL error handling.
What should happen if a statement fails? If xact_abort is on the transaction is rolled back and the execution of the batch stops, but if xact_abort is off the transaction remains open and then the batch continues to execute. This can and will lead to lots of problems.|||Do you know of a good site I can go to where I can learn how to write it? I just starting to learn TSQL and not to sure how I would go about creating a proper @.@.ERROR message. Does the @.@.ERROR have to return a value to the application or does it stay with in the db? Thank for the heads up.|||Are you using 2000 or 2005?

@.@.ERROR is the only way in 2000, but as I said, in 2005 you should rather use TRY...CATCH.|||and you probably should use scope_identit() instead|||Linky! (http://codebetter.com/blogs/john.papa/archive/2006/04/07/142503.aspx)
I did not know that :)|||Are you using 2000 or 2005?

@.@.ERROR is the only way in 2000, but as I said, in 2005 you should rather use TRY...CATCH.

I am using 2000

Monday, March 12, 2012

MSSQLSERVER is MIA

To start a named instance of SQL Server

    On the Start menu, point to All Programs, point to

    Microsoft SQL Server 2005, point to Configuration Tools, and then

    click SQL Server Configuration Manager.

    In SQL Server Configuration Manager, expand Services, and

    then click SQL Server (MSSQLSERVER).

There is no MSSQLSERVER to click!!!!!!!!

If you open services.msc (services page), is MSSQLSERVER listed there? Do you have the appropriate WMI permissions? Try this article to see if it applies:

http://msdn2.microsoft.com/en-us/library/ms188690.aspx

Thanks,
Sam Lester (MSFT)