Friday, March 23, 2012
How controls a range of dates?
difference between two dates is not superior to two months.
Exists some way to control the dates before clicking the button of "View
Report"?
Thanks,On 28 Jun., 12:18, Cetel Sistemas
<CetelSiste...@.discussions.microsoft.com> wrote:
> I have a report that asks for two dates and wanted to control that the
> difference between two dates is not superior to two months.
> Exists some way to control the dates before clicking the button of "View
> Report"?
> Thanks,
Hi
If I understand you right, I think a solution would be to make the
second date dataset dependent of the first selected date parameter.
You could use the datedif() function. In that way you only display
dates for the second date that in is the allowed range.
-Henrik.
how control to Tempdb Growth
Hi all
I am using Sql Server 2000. My application deals with lot data in the db(some tables have data in the range of 34 million records to 50 million records). When i run my application the tempdb grows upto 70 GB and i am getting the error Disk out of space.
How to control this tempdb growth?
Note - No Index or Keys are defined on those tables.
Removed those keys to improve the performance of another application which uses the same database.
Sankar
I think you gave the solution yourself. Removing the indexes will cause a lot of hash joins which in its turn causes tempdb usage.
You really should consider using indexes. The only time indexes can cause you grief is when loading or inserting massive amounts of data and you have lots of indexes. If this is not the case maybe your storage subsystem is simply not well scaled for the database.
WesleyB
Visit my SQL Server weblog @. http://dis4ea.blogspot.com
|||Tempdb is the workarea for the instance. u need to findout what consume TEMPDB more. Whether there is any open transaction(DBCC OPENTRAN) . Droping of index is not a solution at all rather you must see the query and create proper indexes. I believe your tempdb Transaction log is growing not the data file . in that case you can shrink the log also.
Madhu
|||No i dont have permission to create index now as the same database is used by other applications also ....|||Then you will probably have to live with the fact that you need a big tempdb.
WesleyB
Visit my SQL Server weblog @. http://dis4ea.blogspot.com
Wednesday, March 21, 2012
how come the validation doesn't seem to end keep on running?
Hi folks,
it is me again. Just want to enquire how come with the control flow of the Data flows been set appropriately, why when it is executed manually in the sql server 2005 file system, the validation shows the incorrect flow of data flows been executed and doesn't seem to end? Thanks in advance
Regards,
Ken
Hi Ken,
It's probably just me combined with the fact I've had no coffee yet, but I don't follow. Can you restate the issue?
Thanks,
Andy
Hi Andy,
Thanks again for helping this newbie. Ok I have input my package into the SQL Server 2005 file system located under Stored Packages. I run them manually which displays a validation report on its progress. But i notice from the validation report that it doesn't run the validation check as how I drew the flow of the components and it seems to be running endlessly. Is there a way to edit the package so that it can signal the end of the package.
|||Hi Ken,
You are most welcome - I was a newbie myself not long ago.
If I'm understanding you correctly, either your package is stuck in Validation (or appears to be) or stuck in execution (or appears to be).
If the package is stuck in validation, you can change the Package level property DelayValidation to True. The package will load and attempt to run. Any errors will likley cause it to crash, but it may give you insight into why it is behaving in this fashion.
If the package is stuck in execution, I suggest you implement logging. Also consider custom logging using Execute SQL Tasks on the Control Flow and in OnError event handlers.
Hope this helps,
Andy
|||Are you executing child packages from a parent package, by any chance?How come I can connect to a database through a datasource control, but not code?
Hi I am trying to open a database connection to a Northwind database. I can open it with a datasource control and return data to a gridview, but can't programically. I get a sqlexception error. this is ust for learning.
Protected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.Click
Dim SAs New SqlConnection
Dim builderAs New SqlConnectionStringBuilder
builder("Data Source") =".\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF"
builder("Integrated Security") =True
builder("Connect Timeout") = 30
builder("User Instance") =True
S.ConnectionString = builder.ConnectionString
Me.Label1.Text = S.ConnectionString
S.Open()
Me.Label2.Text = S.State.ToString
S.Close()
Me.Label3.Text =Me.SqlDataSource1.ConnectionString.ToString
End Sub
The text in label2 and Label three are identical except there are "" around the datasource.
How come I can connect through the datasource control but not through code?
TallMike:
I get a sqlexception error.
What's the exception?|||
I pasted at the bottom of the reply error below. I tried removing the " " but get a syntax error at
builder("Data Source") =".\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF"
Label1 reads
Data Source=".\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF";Integrated Security=True;Connect Timeout=30;User Instance=True
Label2 reads "Closed"
Label3 reads
Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True
I tried running this code but using the ASPNETDB database in my app_code folder, cause I thought it might be a permissions thing and I didn't set any permission after I downloaded Northwind from MS, but I got the same results
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)
|||Seems the connection string is not valid? Check the connectionString refering to 'SqlConnection.ConnectionString Property' topic in VS2005 Documentation.
FYI, here is a typical connection string:
"Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=Northwind;server=(local)"|||
The connection string you mentioned is for a database on a server. I am trying to connect to a SQL Express database file. The first string in my example works the second doesn't. The only difference is the " "., but you can't use the connection builder without them.
Mike
|||These two ways workS.ConnectionString ="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True"S.ConnectionString = ConfigurationManager.ConnectionStrings(1).ToStringThis way doesn't
builder(
"Data Source") =".\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF"builder(
"Integrated Security") =Truebuilder(
"Connect Timeout") = 30builder(
"User Instance") =TrueI give up
should be 2:builder("Data Source") =".\SQLEXPRESS;AttachDbFilename=C:\SQL\NORTHWND.MDF"
builder("Data Source") =".\SQLEXPRESS"sql
builder("AttachDbFilename")="C:\SQL\NORTHWND.MDF"
Monday, March 12, 2012
How can we control the recursion in CTE?
Hi,
I would like to have some sort of control to recursive CTE, i.e. the query result should be generated level by level.
By default, it looks like this:
levels parentid, categoryid category name
--
1 0 1 aaa
2 1 100 bbb
2 1 101 ccc
2 1 102 ddd
3 102 200 xxx
3 102 201 yyy
4 201 300 zzz
5 300 400 qqq
3 101 210 ppp
....
How can I control the JOIN so that sql server query engine will process join level by level? the CTE I used as following:
with cte(levels, parentid, categoryid, title) as (
select 1,
parentid,
categoryid,
title
from categories
where parentid = 0
union all
select p.levels+1,
c.parentid,
c.categoryid,
c.title
from cte p join categories c on p.categoryid = c.parentid
)
select *
from cte
Thanks
Bill:
If what you want is just to sort the data by level, a simple order by will do -- something like:
declare @.categories table
( levels int,
parentId int,
categoryId int,
title varchar(10)
)
insert into @.categories
select 1,0,1,'aaa' union all
select 2,1,100,'bbb' union all
select 2,1,101,'ccc' union all
select 2,1,102,'ddd' union all
select 3,102,200,'xxx' union all
select 3,102,201,'yyy' union all
select 4,201,300,'zzz' union all
select 5,300,400,'qqq' union all
select 3,101,210,'ppp';with cte(levels, parentid, categoryid, title) as (
select 1,
parentid,
categoryid,
title
from @.categories
where parentid = 0
union all
select p.levels+1,
c.parentid,
c.categoryid,
c.title
from cte p join @.categories c on p.categoryid = c.parentid
)
select *
from cte order by levels, categoryId/*
levels parentid categoryid title
-- -- -- -
1 0 1 aaa
2 1 100 bbb
2 1 101 ccc
2 1 102 ddd
3 102 200 xxx
3 102 201 yyy
3 101 210 ppp
4 201 300 zzz
5 300 400 qqq
*/
However, now that I think about it, I think you are asking a different question; hold on and I will get a second example.
|||What do you mean "the query result should be generated level by level." There is never any guarantee what the result will look like unless you order it. What order do you want to achieve? Based on your generated level by level question, I would guess:
...
select *
from cte
order by levels
|||
My knee-jerk reaction to the question was the same as Louis' reaction. What I often find is that this question is intended to ask how do you display the data in tree order. That is a very different proposition. Is this more like what you are looking for:
|||
;with cte(levels, parentid, categoryid, tree, title) as (
select 1,
parentid,
categoryid,
cast(str(categoryId, 11) as varchar(120)),
title
from @.categories
where parentid = 0
union all
select p.levels+1,
c.parentid,
c.categoryid,
cast(tree + '/' + str(c.categoryId, 11) as varchar(120)),
c.title
from cte p join @.categories c on p.categoryid = c.parentid
)
select levels,
parentId,
categoryId,
title,
replace(tree, ' ', '') as tree
from cte order by tree/*
levels parentId categoryId title tree
-- -- -- - -
1 0 1 aaa 1
2 1 100 bbb 1/100
2 1 101 ccc 1/101
3 101 210 ppp 1/101/210
2 1 102 ddd 1/102
3 102 200 xxx 1/102/200
3 102 201 yyy 1/102/201
4 201 300 zzz 1/102/201/300
5 300 400 qqq 1/102/201/300/400
*/
Thanks Kent/Louis,
Please refer to this thread: http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=473895&SiteID=17.
Euan's codes work perfect for a small table, but mine is pretty large, I want the CTE returning me maximum 20 levels of result, I did use [OPTION (MAXRECURSION 20)] in my query, but because the statement will terminate first when it reaches maximum levels, in this case, ORDER BY won't work.
My result set looks like this:
Levels Pathid Paths
1 96 40885>96
1 98 40885>98
....
1 60532 40885>60532
2 193 40885>60532>193
2 194 40885>60532>194
....
2 60524 40885>60532>60524
3 698 40885>60532>60524>698
3 915 40885>60532>60524>915
...
3 60527 40885>60532>60524>60527
4 3068 40885>60532>60524>60527>3068
4 4022 40885>60532>60524>60527>4022
...
4 60530 40885>60532>60524>60527>60530
5 10760 40885>60532>60524>60527>60530>10760
5 20365 40885>60532>60524>60527>60530>20365
...
please note, above pattern is very interesting, what I really want here is: I'd like to have the next level results are all from previous level, NOT just last record.
Thanks
|||Did Kent's query answer you with the path? It seems to be the same (other than the fact that you are not returning the root node). A query like that was going to be my next suggeston.
Instead of MAXRECURSION, you can also limit the level value in the where clause to make it stop too:
;with cte(levels, parentid, categoryid, tree, title) as (
select 1,
parentid,
categoryid,
cast(str(categoryId, 11) as varchar(120)),
title
from @.categories
where parentid = 0
union all
select p.levels+1,
c.parentid,
c.categoryid,
cast(tree + '/' + str(c.categoryId, 11) as varchar(120)),
c.title
from cte p join @.categories c on p.categoryid = c.parentid
where p.levels < 2 --this will get level one and two only (because p.levels + 1)
)
select levels,
parentId,
categoryId,
title,
replace(tree, ' ', '') as tree
from cte
order by tree
levels parentId categoryId title tree
-- -- -- - --
1 0 1 aaa 1
2 1 100 bbb 1/100
2 1 101 ccc 1/101
2 1 102 ddd 1/102
|||Thanks Louis , that works
Bill
Wednesday, March 7, 2012
How can I use the Variables in SQL Execute SQL task?
I define a package variables "varOutTable" and "varFromTable".
and I insert a SQL Execute SQL Task into Control Flow
my sql command is
"Select * into @.[User::varOutTable] from @.[User::varFromTable]"
but the task failed,
it seems that sql task can't get the varOutTable and varFromTable
How can I use the Variables in SQL Execute SQL task?
thanks!!
Use an expression to build your SQL statement. This is:
Open SQL Task editor|||
thank for your reply.
you are right,
it runs great now.
|||Will this work for a select count(*)?|||agentf1 wrote:
Will this work for a select count(*)?
Why not? A select count(*) would work just like a select * does.... So yes, it would work.|||Just make sure you add an alias to the column (eg. Count(*) as MyCount) and the result set uses the same name (MyCount)....|||I am doing this, my SQL looks like Select count(*) as recordcount from table_name. My variable is set up in ResultSet on the task and is an object.|||Are there any examples of doing a select count(*) into a variable? For some reason when displaying my variable it looks like it contains -1.|||
agentf1 wrote:
Are there any examples of doing a select count(*) into a variable? For some reason when displaying my variable it looks like it contains -1.
That's because your variable is of OBJECT type. If you're returning one row, one value, you can use an integer data type (in this case).|||I am, thanks. I will try this.|||When changed to int32 I get the following error message.
Error: 0xC001F009 at D3OLNAC3: The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "select count(*) as recordcount from loan_auj" failed with the following error: "The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL Task
Warning: 0x80019002 at D3OLNAC3: The Execution method succeeded, but the number of errors raised (3) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS package "D3OLNAC3.dtsx" finished: Failure.|||
That should work. Make sure ResultSet property is set to single row; the result set page you have a resultsetname RecordCount that points to a SSIS variable and that variable is Int32.
If all this is fine; then post all the details of you Execute SQL task to see other potential causes of error
|||That was it, I needed to change result set to single row. Thanks.
How can I use the Variables in SQL Execute SQL task?
I define a package variables "varOutTable" and "varFromTable".
and I insert a SQL Execute SQL Task into Control Flow
my sql command is
"Select * into @.[User::varOutTable] from @.[User::varFromTable]"
but the task failed,
it seems that sql task can't get the varOutTable and varFromTable
How can I use the Variables in SQL Execute SQL task?
thanks!!
Use an expression to build your SQL statement. This is:
Open SQL Task editor|||
thank for your reply.
you are right,
it runs great now.
|||Will this work for a select count(*)?|||agentf1 wrote:
Will this work for a select count(*)?
Why not? A select count(*) would work just like a select * does.... So yes, it would work.|||Just make sure you add an alias to the column (eg. Count(*) as MyCount) and the result set uses the same name (MyCount)....|||I am doing this, my SQL looks like Select count(*) as recordcount from table_name. My variable is set up in ResultSet on the task and is an object.|||Are there any examples of doing a select count(*) into a variable? For some reason when displaying my variable it looks like it contains -1.|||
agentf1 wrote:
Are there any examples of doing a select count(*) into a variable? For some reason when displaying my variable it looks like it contains -1.
That's because your variable is of OBJECT type. If you're returning one row, one value, you can use an integer data type (in this case).|||I am, thanks. I will try this.|||When changed to int32 I get the following error message.
Error: 0xC001F009 at D3OLNAC3: The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "select count(*) as recordcount from loan_auj" failed with the following error: "The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL Task
Warning: 0x80019002 at D3OLNAC3: The Execution method succeeded, but the number of errors raised (3) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS package "D3OLNAC3.dtsx" finished: Failure.|||
That should work. Make sure ResultSet property is set to single row; the result set page you have a resultsetname RecordCount that points to a SSIS variable and that variable is Int32.
If all this is fine; then post all the details of you Execute SQL task to see other potential causes of error
|||That was it, I needed to change result set to single row. Thanks.