Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Thursday, March 29, 2012

Foreach variable cannot be applied

I have created a foreach container to capture values from a query and run a script for each line. For some reason though I can't get past the variable mapping.

The SQL Task that is linked to the Foreach container is somthing like this:

SELECT str1, str2, str2, nValue1, nValue2

FROM MyTable

In the SQL Task I've set the following

ResultSet = Full Result Set

Connection Type = OLE DB

Result Name = 0

I've created the following Variables with a Package scope

s1 as String

s2 as String

s3 as String

n1 as Double

n2 as Double

When I run the package I get the following errors

Foreach variable mapping number 4 to variable "User : : n1" cannot be applied

Foreach variable mapping number 5 to variable "User : : n2" cannot be applied

The data type of nValue1 and nValue2 in MyTable are both numeric(19,4)

In setting the variable types in the package it seems that the closest to numeric(19,4) would be double. Is this why it is failing? Is there any way around it? I just need to pass the variables which are numeric and have decimal places.

Any insight would be greatly appreciated.

Regards,

Bill

See if this blog post helps you:

http://rafael-salas.blogspot.com/2006/12/import-header-line-tables-into-dynamic_22.html

|||

Thanks for the pointer, I found that if I cast the numeric fields in my query to float that the mapping seemed to pass the variables ok.

Regards,

Bill

Monday, March 26, 2012

ForEach from query

Hi All

I'm sure this is a simple thing to do, but I'm new to SSIS and trying to catch up fast.

I want to execute a query on the database which will give me a path and a filespec, say:

c:\apps\testapp1

and

fred*.csv

No problems here.

I then want to feed them into a ForEach loop and interate through all the files matching the filespec at that location. I can't figure this out at all.

Thanks for you help in advance.

FG

http://blogs.conchango.com/jamiethomson/archive/2005/05/30/1489.aspx

-Jamie

|||

Jamie's blog has good info on how to use the ForEach loop container with the ForEachFile enumerator. You can supply a filepath and extenstion with wildcard, fetch back filenames and update a connection strimg. Good stuff.

But I think what you were asking was how to dynamically update the enumerator with different paths and filenames? First it might depend on what your really trying to do.

If you just want to stream in the files then you can also not bother with the loop and instead update the connection string of a 'multiflatfile' connection manager with a property expression of what the file info should be. The key diffference between the multiflat file is that it will accept wildcards...so it can take c:\test\*.txt and the flat file source that uses that conection manager will just load all of the files. So, its functionally different than Jamies route...both have their uses. Looping over the files will load them one at a time, starting/stoping the dataflow each time BUT you can get file specific information such as useing rowcount transform. If you used a rowcount with the wildcard approach and multifileconnection mgr then you just get 1 rowcount result which would include all rows from all files. Again, each method has its place.

Now I think what you really are asking is how to tweak on the fly the folder (directory) and files (fielspec). Well, unfortunately you cannot use property expressions on those properties. Its a current limitation. They are not really properties of the ForEach Container but of the specific enumerator (ForEachFile) which you chose. However you can do it indirectly, using Configurations and having 2 packages, one calling the other, passing in the appropriate new values.

So the parent package uses and ExecuteSQL task to fetch the inforation from a table,returning "path" and "extension" to 2 varirables, all defined in the ExecuteSQL task.

You create a 2nd package with a For Each Loop.
Child: you create 'package Configurations' of the type "parent Package Variable'. one maps to the 'filespec' property and one to the 'directory' of the For each loop

Parent: Then from the parent you add an ExecutePackage task which calls the child package.

So flow is...

Parent ExecuteSQL to populate 2 vars
Parent Executes Child Package
Child Configurations are first thing to be 'pulled' from parent as Child package starts
Child ForEach Loop excutes and the appropriate properties are already update

I suggest reading aobut parent package configurations if you have not already. I think I also have a sample I could send you.

Hope that helps

|||

Very many thanks for both replies.

Craig is correct in his understanding of what I am trying to do. ie, get a path and a filespec from the DB and use these to control the ForEach loop. I'm pleased to hear that it can't be done directly at present, I hadn't missed something too obvious!

I will try your suggestion shortly Craig.

Thanks to Jamie for his input too.

FG

Forcing use of an index

Hi
Can you force a query to use a particular index. IF so please let me
know the sql statement syntax.
thanks
Newish
Hi
Take a look at "index hints" topic in the BOL
"Newish" <ahussain3@.gmail.com> wrote in message
news:1164198675.592286.139920@.m7g2000cwm.googlegro ups.com...
> Hi
> Can you force a query to use a particular index. IF so please let me
> know the sql statement syntax.
> thanks
> Newish
>

Forcing use of an index

Hi
Can you force a query to use a particular index. IF so please let me
know the sql statement syntax.
thanks
NewishHi
Take a look at "index hints" topic in the BOL
"Newish" <ahussain3@.gmail.com> wrote in message
news:1164198675.592286.139920@.m7g2000cwm.googlegroups.com...
> Hi
> Can you force a query to use a particular index. IF so please let me
> know the sql statement syntax.
> thanks
> Newish
>

Forcing use of an index

Hi
Can you force a query to use a particular index. IF so please let me
know the sql statement syntax.
thanks
NewishHi
Take a look at "index hints" topic in the BOL
"Newish" <ahussain3@.gmail.com> wrote in message
news:1164198675.592286.139920@.m7g2000cwm.googlegroups.com...
> Hi
> Can you force a query to use a particular index. IF so please let me
> know the sql statement syntax.
> thanks
> Newish
>

Forcing Specific Distinct Columns....

Hi Guys,

I have a slight problem, a query that i have written produces data with 2 primary keys the same... however, DINSTINCT wont work in this case as the rows are still different...

Is their a way to force 1 column to always be unique?

Heres the query:

SELECT TOP 5 ORDER_ITEM.ItemID AS 'Item ID', ITEM.ItemName AS 'Item Name',
(SELECT SUM(OrdItem2.ItemQuantity) FROM ORDER_ITEM OrdItem2
WHERE OrdItem2.ItemID = ORDER_ITEM.ItemID
) AS Total_Purchased, SUM(ORDER_ITEM.ItemQuantity) AS 'Customer Purchased',
CUSTOMER.customerForename AS 'Customer Forename',
CUSTOMER.customerSurname AS 'Customer Surname'
FROM ITEM, ORDER_ITEM, ORDER_T, CUSTOMER
WHERE ITEM.ItemID = ORDER_ITEM.ItemID
AND ORDER_ITEM.OrderID = ORDER_0510096.OrderID
AND ORDER_T.CustomerID = CUSTOMER.CustomerID
GROUP BY ORDER_ITEM.ItemID, ITEM.ItemName,
CUSTOMER.customerForename, CUSTOMER.customerSurname
ORDER BY Total_Purchased DESC

The query is supposed to select the TOP 5 Products sold as well as selecting the customer that purchased the greatest amount of that item and the amount they purchased.

Currently, i will get 2 duplicate rows (except for customers name and the items the purchased. Like this:

ItemID
8 36 30 Mathew Smith
8 36 6 Tony Wattage

Which is kinda annoying... is there anyway i can prevent this?

And also apart from the Where Joins... is there a more efficient way of writing this?

thx for reading :-)

--PhilkillsDoes no one know any way around this?|||Phil,
The SQL you have posted selecting:
ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
(SELECT SUM(OrdItem2.ItemQuantity)
...does not match with the columns in the dataset you say you are getting:
ItemID
8 36 30 Mathew Smith
8 36 6 Tony Wattage
People are reluctant to respond to threads where the poster has not taken the time to accurately describe the problem.
Also, your problem sounds more like a data issue than a coding issue.|||Phil,
The SQL you have posted selecting:
ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
(SELECT SUM(OrdItem2.ItemQuantity)
...does not match with the columns in the dataset you say you are getting:
ItemID
8 36 30 Mathew Smith
8 36 6 Tony Wattage
People are reluctant to respond to threads where the poster has not taken the time to accurately describe the problem.
Also, your problem sounds more like a data issue than a coding issue.

on the contrary, i left out the data on purpose as it was irrelevent... i was only trying to point out an example of whats wrong... in the "EXAMPLE"
ItemID
8 36 30 Mathew Smith
8 36 6 Tony Wattage
The parts in bold should only appear once.... and the data it should select should be Mathew smith who purchased 30 of that item... 36 is the total amount sold, what i need the query to do... is to only display the person who bought the highest amount of the item that is part of the top 5 best selling items.

another "EXAMPLE":

ItemID Total Sold Heighest Amount sold to 1 Customer Customers Name
1.........30.................30......... ......................Jim
2.........20.................20......... ......................Jam
3.........10.................10......... ......................Flim
4.........5..................5......... .......................Flam
5.........2..................2......... .......................Stam

In this case... only 1 person purchased the items in the top 5...

However, if 5 people purchased the same item... the query would return:

ItemID Total Sold Heighest Amount sold to 1 Customer Customers Name
1.........30.................5.......... .....................Jim
1.........30.................5.......... .....................Jam
1.........30.................5.......... .....................Flim
1.........30.................5.......... .....................Flam
1.........30.................10......... .....................Stam

Notice how it returned the TOP 1 Item instead of the TOP 5 items?

The data is correct... the query is wrong... which is why i asked if i could put a constraint on the data returned saying that ItemID MUST be unique... unless ofcourse there is a better way to do it ;p

I hope this more accurately describes the problem i am having. :-)

--Philkills|||You are making this more confusing than it should be.

Lets break it down into parts.

Does this code give you the top five records that you want, without the customer information?
SELECT TOP 5
ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
SUM(ORDER_ITEM.ItemQuantity) AS Total_Purchased
FROM ITEM
INNER JOIN ORDER_ITEM ON ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_ITEM.ItemID,
ITEM.ItemName
ORDER BY SUM(ORDER_ITEM.ItemQuantity) DESC|||You are making this more confusing than it should be.

Lets break it down into parts.

Does this code give you the top five records that you want, without the customer information?
SELECT TOP 5
ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
SUM(ORDER_ITEM.ItemQuantity) AS Total_Purchased
FROM ITEM
INNER JOIN ORDER_ITEM ON ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_ITEM.ItemID,
ITEM.ItemName
ORDER BY SUM(ORDER_ITEM.ItemQuantity) DESC

yep that code gives the top 5 items ^^|||...and now you want the top customer for each of those items?|||...and now you want the top customer for each of those items?

correct...|||OK. I lied. This is complicated, but we are almost there...
Does this return the top CustomerID for each of those orders?:
SELECT ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
SUM(ORDER_ITEM.ItemQuantity) AS Total_Purchased,
CustomerID =
(SELECT TOP 1
ORDER_T.CustomerID
FROM ORDER_ITEM CUSTOMER_ITEM
INNER JOIN ORDER_T ON CUSTOMER_ITEM.OrderID = ORDER_T.OrderID
INNER JOIN CUSTOMER ON ORDER_T.CustomerID = CUSTOMER.CustomerID
WHERE CUSTOMER_ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_T.CustomerID
ORDER BY SUM(CUSTOMER_ITEM.ItemQuantity) DESC,
ORDER_T.CustomerID)
FROM ITEM
INNER JOIN ORDER_ITEM ON ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_ITEM.ItemID,
ITEM.ItemName
ORDER BY SUM(ORDER_ITEM.ItemQuantity) DESC|||OK. I lied. This is complicated, but we are almost there...
Does this return the top CustomerID for each of those orders?:
SELECT ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
SUM(ORDER_ITEM.ItemQuantity) AS Total_Purchased,
CustomerID =
(SELECT TOP 1
ORDER_T.CustomerID
FROM ORDER_ITEM CUSTOMER_ITEM
INNER JOIN ORDER_T ON CUSTOMER_ITEM.OrderID = ORDER_T.OrderID
INNER JOIN CUSTOMER ON ORDER_T.CustomerID = CUSTOMER.CustomerID
WHERE CUSTOMER_ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_T.CustomerID
ORDER BY SUM(CUSTOMER_ITEM.ItemQuantity) DESC,
ORDER_T.CustomerID)
FROM ITEM
INNER JOIN ORDER_ITEM ON ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_ITEM.ItemID,
ITEM.ItemName
ORDER BY SUM(ORDER_ITEM.ItemQuantity) DESC

Theres no table called CUSTOMER_ITEM... However, i have edited it to return the top customerID correctly.

SELECT ORDER_ITEM.ItemID AS 'Item ID',
ITEM.ItemName AS 'Item Name',
SUM(ORDER_ITEM.ItemQuantity) AS Total_Purchased,
CustomerID =
(SELECT TOP 1
ORDER_T.CustomerID
FROM ITEM
INNER JOIN ORDER_ITEMOrdItem2 ON ITEM.ItemID = OrdItem2.ItemID
INNER JOIN ORDER_T ON OrdItem2.OrderID = ORDER_T.OrderID
INNER JOIN CUSTOMER ON ORDER_T.CustomerID = CUSTOMER.CustomerID
WHERE OrdItem2.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_T.CustomerID
ORDER BY SUM(ORDER_ITEM.ItemQuantity) DESC,
ORDER.CustomerID)
FROM ITEM
INNER JOIN ORDER_ITEM ON ITEM.ItemID = ORDER_ITEM.ItemID
GROUP BY ORDER_ITEM.ItemID,
ITEM_0510096.ItemName
ORDER BY SUM(ORDER_ITEM.ItemQuantity) DESC|||ok, so i can display the customer ID... now how do i display the rest of the customer info ... ^_^|||Am i assuming that no one knows the answer? :confused:

lol, kinda funny a problem that even professionals can't figure out :p|||lol, kinda funny a problem that even professionals can't figure out :poh stop

yes, there are a lot of professionals here

what makes you think they want to be your personal free development center?

ask a question, get an answer, but keep modifying your questions to get more and more and more support as you struggle your way through something that seems to be quite challenging for you... well, there eventually comes a point where people will just go on to the next person

good luck, phil

:)|||oh stop

yes, there are a lot of professionals here

what makes you think they want to be your personal free development center?

ask a question, get an answer, but keep modifying your questions to get more and more and more support as you struggle your way through something that seems to be quite challenging for you... well, there eventually comes a point where people will just go on to the next person

good luck, phil

:)

Eh?, i asked 1 question in this thread... and simply gave more info... in my other posts...

If your refering to my other questions that i've asked around the forum... well, they are pretty much unrelated to this question. I have done a lot of research on SQL queries and the only questions i've asked are related to areas that i have found very difficult to find an answer to.

So as a last resort i turned to this support forum, now i realise your doing this out of the kindness of your heart (i think) and for that im grateful. I too help people, but my area of expertise is with C++/Other languages, i on the other hand will help people regardless of the complexity of the problem, infact the more complex the better :p keeps things interesting.

In regards to my original point about no one being able to solve the problem... well, that was based on the posts inside this thread:

OK. I lied. This is complicated, but we are almost there...

He admitted himself that this was complicated, still being new to SQL i do not yet know all of its limits... but when a proffessional admits that something is complicated, i would say its a pretty good indication that it actually is complicated...

When he never replied after that post... i just assumed that he gave up and admitted defeat... i.e. its impossible to do.... atleast efficiently.

So perhaps next time, before jumping in and making assumptions... you should consider all the facts and why i might have said such words.|||When he never replied after that post... i just assumed that he gave up and admitted defeat... i.e. its impossible to do.... atleast efficiently.
I.....already put a lot of time in helping you with this.
YOU...are impatient and rude.
I....did not log in over the weekend to do your work for you.
YOU...can figure out the rest yourself, loser.|||I.....already put a lot of time in helping you with this.
YOU...are impatient and rude.
I....did not log in over the weekend to do your work for you.
YOU...can figure out the rest yourself, loser.

I.... was not intending to be rude
YOU.... Misinterpreted my point.. obviously thinking i was taking a dig at you or your skill when i was not...
I.... Appreciate all your help so far
YOU.... Probably won't even read this :p

It's up to you whether you help me or not i suppose... but just for the record... the only reason i may have seemed slightly impatient was due to the ever approaching deadline :confused:|||as the old saying goes, "failure to plan on your part does not constitute an emergency on our part"

i'm sorry about your homework assignment coming due real soon, but that's life

if you would like to start a new thread, we can close this one and let it fade into the archives...|||Several times you bumped this thread by implying that people here were either too lazy or too incompetent to help you.

And the fact that now it turns out that this was some sort of homework assignment irks me even more.|||Not to bump a thread that seems to have everyone up in arms, but...

I like to try to solve these "puzzles", just to see if I can.

I understand the question as:
Find the top 5 items sold, the top customer for that item, how much
that customer bought, and how much - in total - of the item sold.

Using my own data, I came up with this:

SELECT TOP 5 ORDER_DETAIL.PRODUCT,
ORDER_HEADER.SHIP_TO AS CUST_ID,
SUM(ORDER_DETAIL.SHIP_QTY) AS CUST_SOLD,
ITEM_TTL.TTL_SOLD
FROM ORDER_HEADER INNER JOIN
ORDER_DETAIL ON ORDER_HEADER.ORDER_ID = ORDER_DETAIL.ORDER_ID
INNER JOIN (SELECT TOP 5 ORDER_DETAIL.PRODUCT,
SUM(ORDER_DETAIL.SHIP_QTY) AS TTL_SOLD
FROM ORDER_HEADER INNER JOIN
ORDER_DETAIL ON
ORDER_HEADER.ORDER_ID=ORDER_DETAIL.ORDER_ID
WHERE (NOT (ORDER_HEADER.SHIP_DATE IS NULL))
GROUP BY ORDER_DETAIL.PRODUCT
ORDER BY SUM(ORDER_DETAIL.SHIP_QTY) DESC) AS ITEM_TTL ON ORDER_DETAIL.PRODUCT=ITEM_TTL.PRODUCT
WHERE (NOT (ORDER_HEADER.SHIP_DATE IS NULL)) AND (ORDER_DETAIL.PRODUCT IN
(SELECT TOP 5 ORDER_DETAIL.PRODUCT
FROM ORDER_HEADER INNER JOIN
ORDER_DETAIL ON
ORDER_HEADER.ORDER_ID = ORDER_DETAIL.ORDER_ID
WHERE (NOT (ORDER_HEADER.SHIP_DATE IS NULL))
GROUP BY ORDER_DETAIL.PRODUCT
ORDER BY SUM(ORDER_DETAIL.SHIP_QTY) DESC))
GROUP BY ORDER_HEADER.SHIP_TO, ORDER_DETAIL.PRODUCT, ITEM_TTL.TTL_SOLD
ORDER BY SUM(ORDER_DETAIL.SHIP_QTY) DESC

This returns:
Product Cust_ID Cust_Sold Ttl_Sold
F.........12.........1035......2700
B.........15.........672.......2457
D.........7.........1243......1972
C.........91.........814.......1757
A.........18.........593.......1549|||I suspect the TOP 5 in the outer query is redundant, since you have it included in your nested subquery.|||Several times you bumped this thread by implying that people here were either too lazy or too incompetent to help you.

And the fact that now it turns out that this was some sort of homework assignment irks me even more.

again suprise suprise you jump to conclusions that you think are right... i was NOT implying anything... if something can't be done... it can't be done... thats why i said what i did...

Not to bump a thread that seems to have everyone up in arms, but...

I like to try to solve these "puzzles", just to see if I can.

I understand the question as:
Find the top 5 items sold, the top customer for that item, how much
that customer bought, and how much - in total - of the item sold.

Using my own data, I came up with this:

Code:
SELECT TOP 5 ORDER_DETAIL.PRODUCT,
ORDER_HEADER.SHIP_TO AS CUST_ID,
SUM(ORDER_DETAIL.SHIP_QTY) AS CUST_SOLD,
ITEM_TTL.TTL_SOLD
FROM ORDER_HEADER INNER JOIN
ORDER_DETAIL ON ORDER_HEADER.ORDER_ID = ORDER_DETAIL.ORDER_ID
INNER JOIN (SELECT TOP 5 ORDER_DETAIL.PRODUCT,
SUM(ORDER_DETAIL.SHIP_QTY) AS TTL_SOLD
FROM ORDER_HEADER INNER JOIN
ORDER_DETAIL ON
ORDER_HEADER.ORDER_ID=ORDER_DETAIL.ORDER_ID
WHERE (NOT (ORDER_HEADER.SHIP_DATE IS NULL))
GROUP BY ORDER_DETAIL.PRODUCT
ORDER BY SUM(ORDER_DETAIL.SHIP_QTY) DESC) AS ITEM_TTL ON ORDER_DETAIL.PRODUCT=ITEM_TTL.PRODUCT
WHERE (NOT (ORDER_HEADER.SHIP_DATE IS NULL)) AND (ORDER_DETAIL.PRODUCT IN
(SELECT TOP 5 ORDER_DETAIL.PRODUCT
FROM ORDER_HEADER INNER JOIN
ORDER_DETAIL ON
ORDER_HEADER.ORDER_ID = ORDER_DETAIL.ORDER_ID
WHERE (NOT (ORDER_HEADER.SHIP_DATE IS NULL))
GROUP BY ORDER_DETAIL.PRODUCT
ORDER BY SUM(ORDER_DETAIL.SHIP_QTY) DESC))
GROUP BY ORDER_HEADER.SHIP_TO, ORDER_DETAIL.PRODUCT, ITEM_TTL.TTL_SOLD
ORDER BY SUM(ORDER_DETAIL.SHIP_QTY) DESC
This returns:
Product Cust_ID Cust_Sold Ttl_Sold
F.........12.........1035......2700
B.........15.........672.......2457
D.........7.........1243......1972
C.........91.........814.......1757
A.........18.........593.......1549

thank you very much mate for putting in the effort to solve this conundrum
:-). I appreciate it i really do ^^|||Am i assuming that no one knows the answer? :confused:
lol, kinda funny a problem that even professionals can't figure out :p
i on the other hand will help people regardless of the complexity of the problem,
When he never replied after that post... i just assumed that he gave up and admitted defeat...
YOU.... Probably won't even read this
You were acting like a complete twit. The fact that you seem oblivious to this I will chalk up to immaturity. Hopefully, you will soon grow up enough to be respectful to people who are volunteering their time and expertise to help you out.|||I suspect the TOP 5 in the outer query is redundant, since you have it included in your nested subquery.

I intended the top 5 in the outer query to pull the top 5 customers, while
the top 5 in the nested query is pulling just the top 5 products.sql

Forcing Reporting Services to update with new query?

Take a look and see how long the old version of the report is cached for. Andrew Watt MVP - InfoPath wrote in message news:cf32036e-8c31-4697-b1aa-a45e1bf9089c@.discussions.microsoft.com... >I had a minor error in my query that i corrected, but RS for some reason
> is still using the 'old' query rather than the new 1. >
> I have redeployed the report, rebooted the machine and restarted IIS,
> but to no avail, it is still using the incorrect 'old query. > >
> Any help?
>I had a minor error in my query that i corrected, but RS for some reason is still using the 'old' query rather than the new 1.

I have redeployed the report, rebooted the machine and restarted IIS, but to no avail, it is still using the incorrect 'old query.
Any help?|||There are many reasons that this could be happening, for example, did you check that there were no errors in the build/deploy. Is the report being deployed to the correct server and to the correct folder.

Have you tried deleteing the old report then redeploying it, this will help you to determine where this behavior is coming from. If you try this and it still doesn't work then the problem is somewhere in the report project.

Try this and post what happens.|||Thanks, i have indeed deleted the datasource and the report and redeployed them, but still the same problem.
The report works perfectly in VS2005 preview, yet i get the same error when its is deployed
(If i select an @.FromDate from any month besides september i get the error 'The value provided for the report parameter 'FromDate' is not valid for its type. (rsReportParameterTypeMismatch)' )

Here is my code:
I am trying to select clicks between date ranges
SELECT MIN(A.hitDate) AS minDate, D.AffiliateName, B.ProdType, COUNT(DISTINCT A.ipAddress) AS TOTAL
FROM ArchiveApplyTracking A LEFT OUTER JOIN
ExpertMatchConfiguration.dbo.Affiliates D ON A.affiliateID = D.AffiliateID LEFT OUTER JOIN
ArchiveCampaignIncoming C ON A.campaignID = C.ID LEFT OUTER JOIN
ExpertMatchConfiguration.dbo.ProductType B ON A.productTypeID = B.ProdNo
WHERE (A.hitDate >=@.FromDate) and (A.hitDate <@.ToDate) AND (A.ipAddress NOT IN
(SELECT ipAddress
FROM [ExpertMatchTracking].[dbo].ipTracking)) AND (B.ProdType IN (@.ProductType)) AND (B.ProdType NOT LIKE 'refused%') AND (A.deal = 1) AND (D.AffiliateName IN (@.AffiliateName)) AND (B.ProdType NOT LIKE '%prequalify%')
GROUP BY D.AffiliateName, B.ProdType
ORDER BY D.AffiliateName
There must be an error in the deployment as it works 100% in the preview
Thanks for your input
|||

Only thing I can think of is the format of the date. If the format is incorrect then it will appear to work for some dates but then it will not work for others.

|||Thanks, i cant fathom why it works fine in preview, but falls over completly in the deployed report. Nor do i think there is anything from with the date format, it is pretty straight-forward.
But thanks anyway
|||You could try to delete existing report from report server before deploying.

Forcing Query Plans

Is it possible to force a query plan on a Stored procedue. I have attempted the following and i receive a Incorrect syntax near the keyword 'OPTION'. Any ideas?

EXEC testdatabases..testprocedure

OPTION (USE PLAN N'
<ShowPlanXML xmlns=
"http://schemas.microsoft.com/sqlserver/2004/07/showplan" Version="0.5"
Build="9.00.1187.07">
<BatchSequence>
<Batch>
<Statements>
...
</Statements>
</Batch>
</BatchSequence>
</ShowPlanXML>
')
GO

You could use OPTION and USE PLAN only with SELECT/INSERT/DELETE/STATEMENTS. So move your plan in body of stored procedures.

If you couldn't change your stored procedure use Plan Guide by sp_create_plan_guide http://msdn2.microsoft.com/en-us/library/ms179880.aspx

Forcing display of QA's buffer

How can I force the contents of Query Analyzer's buffer to display to the
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> > How can I force the contents of Query Analyzer's buffer to display to
the
> > screen?
> >
> > A stored proc has some debug PRINT statements in it. The proc takes a
> long
> > time to execute and the PRINT statements don't display until execution
is
> > complete.
> >
> > Is it possible to force them to display immediately? If so, how?
> >
> >
>|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> > How can I force the contents of Query Analyzer's buffer to display to
the
> > screen?
> >
> > A stored proc has some debug PRINT statements in it. The proc takes a
> long
> > time to execute and the PRINT statements don't display until execution
is
> > complete.
> >
> > Is it possible to force them to display immediately? If so, how?
> >
> >
>|||Good point, just in the habit of using 11.
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> > How about RAISERROR WITH NOWAIT? Watch the messages pane:
> >
> >
> > PRINT 'foo'
> > WAITFOR DELAY '00:00:05'
> > GO
> > RAISERROR('foo', 11, 1) WITH NOWAIT
> > WAITFOR DELAY '00:00:05'
> > GO
> >
> >
> > --
> > http://www.aspfaq.com/
> > (Reverse address to reply.)
> >
> >
> >
> >
> > "Dave" <dave@.nospam.ru> wrote in message
> > news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> > > How can I force the contents of Query Analyzer's buffer to display to
> the
> > > screen?
> > >
> > > A stored proc has some debug PRINT statements in it. The proc takes a
> > long
> > > time to execute and the PRINT statements don't display until execution
> is
> > > complete.
> > >
> > > Is it possible to force them to display immediately? If so, how?
> > >
> > >
> >
> >
>|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
>> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>>
>> PRINT 'foo'
>> WAITFOR DELAY '00:00:05'
>> GO
>> RAISERROR('foo', 11, 1) WITH NOWAIT
>> WAITFOR DELAY '00:00:05'
>> GO
>>
>> --
>> http://www.aspfaq.com/
>> (Reverse address to reply.)
>>
>>
>> "Dave" <dave@.nospam.ru> wrote in message
>> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
>> > How can I force the contents of Query Analyzer's buffer to display to
> the
>> > screen?
>> >
>> > A stored proc has some debug PRINT statements in it. The proc takes a
>> long
>> > time to execute and the PRINT statements don't display until execution
> is
>> > complete.
>> >
>> > Is it possible to force them to display immediately? If so, how?
>> >
>> >
>>
>|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> > THe red error messages are a distraction but I can live with that.
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> > Thanks Aaron
> >
> > That works and it also prints out any unprinted PRINT statements
previous to
> > the RAISERROR.
> >
> > THe red error messages are a distraction but I can live with that.
> >
> > Thank you.
> >
> >
> > "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> > news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> >> How about RAISERROR WITH NOWAIT? Watch the messages pane:
> >>
> >>
> >> PRINT 'foo'
> >> WAITFOR DELAY '00:00:05'
> >> GO
> >> RAISERROR('foo', 11, 1) WITH NOWAIT
> >> WAITFOR DELAY '00:00:05'
> >> GO
> >>
> >>
> >> --
> >> http://www.aspfaq.com/
> >> (Reverse address to reply.)
> >>
> >>
> >>
> >>
> >> "Dave" <dave@.nospam.ru> wrote in message
> >> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> >> > How can I force the contents of Query Analyzer's buffer to display to
> > the
> >> > screen?
> >> >
> >> > A stored proc has some debug PRINT statements in it. The proc takes
a
> >> long
> >> > time to execute and the PRINT statements don't display until
execution
> > is
> >> > complete.
> >> >
> >> > Is it possible to force them to display immediately? If so, how?
> >> >
> >> >
> >>
> >>
> >
> >
>|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?|||SQL Server doesn't send its output to the client immediately as it is generated by the engine. This
is to consume less network resources. And this is the reason why we don't see things like PRINT
immediately after they have been performed. SQL Server will wait until its output buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
the output buffer.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:
>> How can I force the contents of Query Analyzer's buffer to display to the
>> screen?
>> A stored proc has some debug PRINT statements in it. The proc takes a long
>> time to execute and the PRINT statements don't display until execution is
>> complete.
>> Is it possible to force them to display immediately? If so, how?|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
--
http://www.aspfaq.com/
(Reverse address to reply.)

Forcing display of QA's buffer

How can I force the contents of Query Analyzer's buffer to display to the
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?
How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>
|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is
>
|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is
>
|||Good point, just in the habit of using 11.
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>
|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>
|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...[vbcol=seagreen]
previous to[vbcol=seagreen]
a[vbcol=seagreen]
execution
>
|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
|||SQL Server doesn't send its output to the client immediately as it is generated by the engine. This
is to consume less network resources. And this is the reason why we don't see things like PRINT
immediately after they have been performed. SQL Server will wait until its output buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
the output buffer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...[vbcol=seagreen]
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:
|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
http://www.aspfaq.com/
(Reverse address to reply.)

Friday, March 23, 2012

Forcing display of QA's buffer

How can I force the contents of Query Analyzer's buffer to display to the
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is[vbcol=seagreen]
>|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is[vbcol=seagreen]
>|||Good point, just in the habit of using 11.
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...[vbcol
=seagreen]
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous
to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>[/vbcol]|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
previous to[vbcol=seagreen]
a[vbcol=seagreen]
execution[vbcol=seagreen]
>|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a lon
g
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?|||SQL Server doesn't send its output to the client immediately as it is genera
ted by the engine. This
is to consume less network resources. And this is the reason why we don't se
e things like PRINT
immediately after they have been performed. SQL Server will wait until its o
utput buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it fo
rces SQL Server to flush
the output buffer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...[vbcol=s
eagreen]
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
http://www.aspfaq.com/
(Reverse address to reply.)sql

forcing column to appear

I have a matrix that shows figures by year, broken down by months (1-12).
When the query runs and that particular month has not values, the column is
not displayed. I previously came across something regarding the use of a
function to force the columns to appear but can't seem to find it again.
Anyone have a suggestion for doing this? It would be similar to how the PIVOT
in access works.On Jun 6, 10:08 am, brian <b...@.discussions.microsoft.com> wrote:
> I have a matrix that shows figures by year, broken down by months (1-12).
> When the query runs and that particular month has not values, the column is
> not displayed. I previously came across something regarding the use of a
> function to force the columns to appear but can't seem to find it again.
> Anyone have a suggestion for doing this? It would be similar to how the PIVOT
> in access works.
I traditionally look for the columns (value in the pivot column) that
I am expecting in the dataset and if they do not appear union an empty
record with the column name to the returned dataset (as part of the
stored procedure/query that is sourcing the report). Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant

Forcing a set number of result rows in a query

I'm trying to select 5 rows of data from a query. Sometimes there is less than 5 rows of data in the result set.

Is there a way to FORCE a return of 5 rows - even if they don't exist? For example, returning some text such as "No Data" or NULL in the result set?

What I'm doing to return 5 rows of data:

Select top 5 *

From MyTable

I need help modifying this query to make sure I always get 5 rows of data.

Thanks!

There is no pre-defined settings available but you do something below,

Code Snippet

Create table #Data(

Id int,

Name varchar(100)

)

Insert Into #Data Values(1,100)

Insert Into #Data Values(2,100)

Insert Into #Data Values(3,100)

Select Top 5 * From

(

Select Id, Name from #Data

Union ALL

Select NULL, NULL

Union ALL

Select NULL, NULL

Union ALL

Select NULL, NULL

Union ALL

Select NULL, NULL

Union ALL

Select NULL, NULL

)

as Data

Order By Case When Id is NULL Then 1 Else 0 End , ID

|||

Code Snippet

CREATE TABLE #temp (test int)

INSERT INTO #temp SELECT 1

INSERT INTO #temp SELECT 2

INSERT INTO #temp SELECT 3

DECLARE @.counter as int

set @.counter = (SELECT COUNT(*) from #temp)

SELECT * FROM #temp

WHILE @.counter < 5

BEGIN

INSERT INTO #temp SELECT NULL

SET @.counter = @.counter + 1

END

SELECT * FROM #temp

DROP TABLE #temp

Adamus

|||Thanks for the prompt replies - both of these replies were helpful and answered my question!

Forcefully close and remove a database

Does anyone know if it is possible (if I have a very long running query) to
...
1. Kill the running spids in the database (without having them
rollback...which itself would take an eternity). I don't care at this point
whether the database becomes suspect (which off course it probably would).
2. I would then Drop the database.
The only way I have managed to do this in the past is to restart the SQL
Service -which is not a very elegant solution and should be unnecessary (in
theory).
Am I missing a command or an undocumented kill parameter.
Many thanks,
Mark."news.microsoft.com" <nospam@.nospam.com> wrote in message
news:e3VCpplNIHA.4740@.TK2MSFTNGP02.phx.gbl...
> Does anyone know if it is possible (if I have a very long running query)
> to ...
> 1. Kill the running spids in the database (without having them
> rollback...which itself would take an eternity). I don't care at this
> point whether the database becomes suspect (which off course it probably
> would).
> 2. I would then Drop the database.
> The only way I have managed to do this in the past is to restart the SQL
> Service -which is not a very elegant solution and should be unnecessary
> (in theory).
> Am I missing a command or an undocumented kill parameter.
> Many thanks,
> Mark.
>
Try:
ALTER DATABASE db1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
--
David Portas

Forcefully close and remove a database

Does anyone know if it is possible (if I have a very long running query) to
...
1. Kill the running spids in the database (without having them
rollback...which itself would take an eternity). I don't care at this point
whether the database becomes suspect (which off course it probably would).
2. I would then Drop the database.
The only way I have managed to do this in the past is to restart the SQL
Service -which is not a very elegant solution and should be unnecessary (in
theory).
Am I missing a command or an undocumented kill parameter.
Many thanks,
Mark.
"news.microsoft.com" <nospam@.nospam.com> wrote in message
news:e3VCpplNIHA.4740@.TK2MSFTNGP02.phx.gbl...
> Does anyone know if it is possible (if I have a very long running query)
> to ...
> 1. Kill the running spids in the database (without having them
> rollback...which itself would take an eternity). I don't care at this
> point whether the database becomes suspect (which off course it probably
> would).
> 2. I would then Drop the database.
> The only way I have managed to do this in the past is to restart the SQL
> Service -which is not a very elegant solution and should be unnecessary
> (in theory).
> Am I missing a command or an undocumented kill parameter.
> Many thanks,
> Mark.
>
Try:
ALTER DATABASE db1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
David Portas

Forcefully close and remove a database

Does anyone know if it is possible (if I have a very long running query) to
...
1. Kill the running spids in the database (without having them
rollback...which itself would take an eternity). I don't care at this point
whether the database becomes suspect (which off course it probably would).
2. I would then Drop the database.
The only way I have managed to do this in the past is to restart the SQL
Service -which is not a very elegant solution and should be unnecessary (in
theory).
Am I missing a command or an undocumented kill parameter.
Many thanks,
Mark."news.microsoft.com" <nospam@.nospam.com> wrote in message
news:e3VCpplNIHA.4740@.TK2MSFTNGP02.phx.gbl...
> Does anyone know if it is possible (if I have a very long running query)
> to ...
> 1. Kill the running spids in the database (without having them
> rollback...which itself would take an eternity). I don't care at this
> point whether the database becomes suspect (which off course it probably
> would).
> 2. I would then Drop the database.
> The only way I have managed to do this in the past is to restart the SQL
> Service -which is not a very elegant solution and should be unnecessary
> (in theory).
> Am I missing a command or an undocumented kill parameter.
> Many thanks,
> Mark.
>
Try:
ALTER DATABASE db1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
David Portas

Wednesday, March 21, 2012

Force Uniqueness on one column

HI:
If when joining parent and child tables, a query returns multiple entries
for a given parent, how can I limit query to showing only first child? Kind
of like grouping on one field in result set.
Thanks,
CharlieDefine "first".
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:eIegtNg6FHA.632@.TK2MSFTNGP10.phx.gbl...
> HI:
> If when joining parent and child tables, a query returns multiple entries
> for a given parent, how can I limit query to showing only first child?
> Kind
> of like grouping on one field in result set.
> Thanks,
> Charlie
>|||Hi Tom, let me restate..
If query joins a parent table with a child table in a one-to-many relation
the results set will show the parent id repeating for each child. I want
the query to show only one child despite having many. How do I filter join
to limit result set to only one child per parent even though it a parent may
have many child records.
Thanks,
charlie
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
news:unojjUg6FHA.636@.TK2MSFTNGP10.phx.gbl...
> Define "first".
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> "Charlie@.CBFC" <charle1@.comcast.net> wrote in message
> news:eIegtNg6FHA.632@.TK2MSFTNGP10.phx.gbl...
entries
>|||SELECT
Parent.ID
, Child.ID
, Child.Data
FROM
Parent
INNER JOIN
(
SELECT
Child.Parent_ID
, Child.ID
, Child.Data
FROM
Child
INNER JOIN
(
SELECT Parent_ID , MIN( ID ) AS ID FROM Child GROUP BY
Parent_ID
) LowestChildForParent
ON
Child.Parent_ID = LowestChildForParent.Parent_ID
AND
Child.ID = LowestChildForParent.ID
) Child
ON
Parent.ID = Child.Parent_ID
"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:ucEjkag6FHA.744@.TK2MSFTNGP10.phx.gbl...
> Hi Tom, let me restate..
> If query joins a parent table with a child table in a one-to-many relation
> the results set will show the parent id repeating for each child. I want
> the query to show only one child despite having many. How do I filter
join
> to limit result set to only one child per parent even though it a parent
may
> have many child records.
> Thanks,
> charlie
>
> "Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
> news:unojjUg6FHA.636@.TK2MSFTNGP10.phx.gbl...
> entries
>|||Again, define "first". You haven't posted your DDL. We have no idea which
of the child rows is the "first" for a given parent ID.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:ucEjkag6FHA.744@.TK2MSFTNGP10.phx.gbl...
> Hi Tom, let me restate..
> If query joins a parent table with a child table in a one-to-many relation
> the results set will show the parent id repeating for each child. I want
> the query to show only one child despite having many. How do I filter
> join
> to limit result set to only one child per parent even though it a parent
> may
> have many child records.
> Thanks,
> charlie
>
> "Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
> news:unojjUg6FHA.636@.TK2MSFTNGP10.phx.gbl...
> entries
>|||Using min() or max() value for a set of keys in grouping should work. This
will first or last child.
Thanks
"Rebecca York" <rebecca.york {at} 2ndbyte.com> wrote in message
news:437a10a3$0$133$7b0f0fd3@.mistral.news.newnet.co.uk...
> SELECT
> Parent.ID
> , Child.ID
> , Child.Data
> FROM
> Parent
> INNER JOIN
> (
> SELECT
> Child.Parent_ID
> , Child.ID
> , Child.Data
> FROM
> Child
> INNER JOIN
> (
> SELECT Parent_ID , MIN( ID ) AS ID FROM Child GROUP BY
> Parent_ID
> ) LowestChildForParent
> ON
> Child.Parent_ID = LowestChildForParent.Parent_ID
> AND
> Child.ID = LowestChildForParent.ID
> ) Child
> ON
> Parent.ID = Child.Parent_ID
>
> "Charlie@.CBFC" <charle1@.comcast.net> wrote in message
> news:ucEjkag6FHA.744@.TK2MSFTNGP10.phx.gbl...
relation
want
> join
> may
child?
>

Force to complete query, ignore errors

Hi,

I have a big table and want to make a plausibility check of it′s data.

Problem is, that my query stops, if there is an unexpected datatype in one of the rows. But that is it, what i want to filter out of my table with that query and save the result as new correct table.

How can i write a parameter to my query SQL Code, that if a error occurs, the querry resumes and the error line will not displayed in my final querry overview?

In my books and on the net, i don′t found something to this theme ;-(.

Thx in advance.

You should provide additional info
- how is the table outline ?
- which is the unexpected data that breaks your code ?
- which sql server version are you working with ?
- it's a pure t-sql approach or is a mixed ado.net / sql approach ?
- can you post a short version of the t-sql code here ?|||- how is the table outline ?
The table has 30 columns with differnt data's in there. The datatyps are all nvarchar(50) after the flatfile txt Import. But there are some date, text, int and float datats, in there. I will bringt the correct datatyp to the columns later, because i have 80 of such tables, and before i must correct them form wrong lines and merge them after that.

- which is the unexpected data that breaks your code ?

Very very much possible things. A date where a int is expected. A float where a int is expected and and. It′s because the txt-Files i got have many data errors and wrong moved lines in there and i must correct them now.

- which sql server version are you working with ?

SQL Server 2005

- it's a pure t-sql approach or is a mixed ado.net / sql approach ?

I don′t know, but i don′t think ado.net.

- can you post a short version of the t-sql code here ?

[Code]
SELECT TOP (100) PERCENT _Ti, _Pl, _Ve, [_Datum_Time], _Ere, _Sg, _Sm,
FROM dbo.d6020900_ges
WHERE (_Ti < 1) OR
(_Ti > 1000) AND (_Pl < 0) OR
(_Pl > 15) AND (_Ve < 0) OR
(_Ve > 10000) AND (_Ere < - 1) OR
(_Ere > 10) AND (_Sg < N'0') OR
(_Sg > N'356') AND (_Sm < N'0') OR
(_Sm > N'255')
ORDER BY _Ti, _Pl, _Ve, [_Datum_Time]
[\Code]

|||There are different approaches depending on which is the operation you have to do...

First of all don't expect that is a simple task... I don't think you will be able to build a query like the one you posted... there are a lot of implicit conversions that simply cannot work in your case... there's no way to tell SQL to "skip" some row when a conversion fails... you have to build a little "engine" that anayze data column by column.

If you have to correct data in a table, this happens only once, so you can launch a long running query, maybe using a cursor and evaluating on a per row basis...
if this is the case you may also want to use a CLR stored proc... in that case you may fetch your data into a dataset and use standard manipulation/conversion using your favorite language (C#, VB.NET). In that case I think that the use of a CLR SP is fully justified from the improved flexibility in analyzing data, after all string manipulation with the framework is a lot more powerful that T-SQL.

If you have to repeadetly query the data to build a report or something like that... well this is a nightmare... I strongly suggest you to convert your data into a table that has the required data types (integers, datetime and so on), else you may build a bunch of conversion functions and/or a view made up by functions (or computed fields) that may be used to access the data... but, as you probably have already thought, this not a good performance solution.. it would be better to apply those functions only once to migrate your data into a brand new ad-hoc table.

Anyway let me know if you need further info.|||Thx so far.

My biggest problem are the much wrong lines in my Table, so converting in SQL fails and importing the basis txt-flatfile to a table with the correct datatypes fails also.

Is there a way to import only the rows, that are correct and dont stop at the wrong?|||You need to process you data row by row. This can be done
- using a cursor if you want to operate with a pure T-SQL solution
- using an external application (or a CLR stored proc) if you want more power/flexibility
I don't know any other way

You may also add a signature bit to your row that marks the row as dirty so you can filter it out... but again this requires that you process the table line by line.

in pseudo-code this may look like this

OPEN CURSOR
FETCH NEXT DATA INTO FIELD1, FIELD2, ...
WHILE (@.@.FETCH_STATUS = 0) BEGIN
IF DIRTY_DATE(FIELD1) OR DIRTY_INT(FIELD2) OR ... BEGIN
... DO SOMETHING HERE ...
END
FETCH NEXT DATA INTO FIELD1, FIELD2, ...
END

Just a question: why don't you avoid inserting bad rows when you import the txt file ?|||Hm, what u mean with avoid inserting bad rows? The bad rows are allready in my base txt-Files. But they are too large, to check and delete there every single line with the hand.

I don′t know how i can say on the import assistent, that bad rows will not be importet. At my try's the import stops, if a bad row is detected, an i musst correct the line in the txt-file with my own hands, delete the table in the db and then start again the import.

Is there a better way?|||> Hm, what u mean with avoid inserting bad rows?

You have an application that imports the text file into the system... correct ? well in that case the validation must be performed from that application. the data are imported only after validation ha occurred, so you won't have any problem in the db.

> Is there a better way?

I will be explicit, hope you won't offend:
1. who is the mad person that thought such a procedure ? how is possible that your "file-producer" is not able to write a decent file with no errors ? What I would do ? completely reject any file that contains errors.
2. who have designed the table with the nvarchar data only ? hope that you agree that is really a stupid thing... it's like you were trying to program an application with no data types... only pointers and bytes... that's prehistory.
|||O.K. thx, but the produced basis txt Files are corrupt and i have filtered many things before with VBA in excel, but to filter everything, vba and excel are to slow for my masses on files. The basis txt files are so, like I have got them, i can't get new ones or better ones, i must live with them.|||
> i must live with them.

ognuno ha le sue sfighe ...

Monday, March 12, 2012

For/Foreach loop

Hi,

I'm looping through some query data and doing a Script Task check inside the loop on a datetime field.

If the datetime happens before 10 o'clock:

- Store the data row in Table1

If the datetime happens after 10 o'clock:

- Store the data row in Table2

How can I store the datarow inside the loop without inserting it into a database table?

I need to access the data in the next step after the loop. How can I do this?

Thank you very much! Smile

Can you store the values in some variables?

|||

Thanks for the reply.

Yes, I could. But if I'm looping through 100 lines of query data, and I want to store 50 of them, wouldn′t it mean a whole lot of variables to store all the data?

Am I misunderstanding you perhaps?

|||If you have a single source connection for the data and you want to split the rows based on the value of a certain column, used a conditional split, as per previous post, and then write the rows to a raw file for later use.

Other option would be to generate the rows based on the conditions and then write them to variables, as per Jamie's option, and use them later.

Depending on the number of rows and different conditions you have, either option would work. Variable route may give performance / resource problems on large numbers though.|||

MrHat wrote:

Thanks for the reply.

Yes, I could. But if I'm looping through 100 lines of query data, and I want to store 50 of them, wouldn′t it mean a whole lot of variables to store all the data?

Yes it would. Is that a problem?

MrHat wrote:

Am I misunderstanding you perhaps?

I don't think so

-Jamie

FOR XML works differently between Developer and Enterprise Edition in SQL 2005

If I run the same FOR XML query in a Development edition enviornment and a Enterprise Edition environment, the results are different. The query is exactly the same.

Here is the query:

DECLARE @.MessageBody XML
DECLARE @.AuditTable SYSNAME
DECLARE @.SendTrans BIT
DECLARE @.SendAudit BIT
DECLARE @.RecordCount INT
DECLARE @.OperationType CHAR(1)

SET @.RecordCount = @.@.ROWCOUNT
SET @.OperationType = 'U'
SET @.SendTrans = 1
SET @.SendAudit = 1
SET @.AuditTable = 'States'

SELECT @.MessageBody = (
SELECT * FROM
(
SELECT TOP 10
'INSERTED' AS ActionType, @.SendTrans AS SendTrans, @.SendAudit AS SendAudit,
COLUMNS_UPDATED() AS ColumnsUpdated, GETDATE() AS AuditDate,
@.AuditTable AS AuditTable, 'test' AS UserName, @.RecordCount AS RecordCount, *
FROM l_states
)AuditRecord
FOR XML AUTO, ROOT('AuditTable'), BINARY BASE64)

SELECT @.MessageBody

In my DEV env (Developer Edition), this result is produced:
<AuditTable>
<AuditRecord ActionType="INSERTED" SendTrans="1" SendAudit="1" AuditDate="2007-06-22T15:43:12.497" AuditTable="States" UserName="test" RecordCount="1" StateAbbreviation="AK" State="Alaska" />
<AuditRecord ActionType="INSERTED" SendTrans="1" SendAudit="1" AuditDate="2007-06-22T15:43:12.497" AuditTable="States" UserName="test" RecordCount="1" StateAbbreviation="AL" State="Alabama" />
</AuditTable>

In my Enterprise Edition evn, this is the result:
<AuditTable>
<AuditRecord ActionType="INSERTED" SendTrans="1" SendAudit="1" AuditDate="2007-06-22T15:44:48.230" AuditTable="States" UserName="test" RecordCount="1">
<l_states StateAbbreviation="AK" State="Alaska" />
<l_states StateAbbreviation="AL" State="Alabama" />
</AuditRecord>
</AuditTable>

Does anyone have any idea what might be wrong? Any help is greatly appreciated.
Tim

Tim,

What is the results of @.@.VERSION on both servers? (I suspect a difference in versions...)