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

Wednesday, March 28, 2012

How can I compare datetime in a query?

I have a table with the following columns

company_Id employee_id logon_time_id logoff_time start_valid_period end_valid_period

Employee's working time should only be counted if it is between start_valid_period and end_valid_period

So, if I have for employee1 from company1

logon_time_id = 04/07/2006 11:00
loggoff_time = 04/07/2006 12:20
start_valid_period = 04/07/2006 12:10
end_valid_period = 04/07/2006 12:30

I should consider 04/07/2006 12:10 as the initial datetime, 04/07/2006 12:20 as the final datetime, and count only 10min of work to him. In code:

if(logon_time_id < start_valid_period) initialDatetime = start_valid_period else initialDatetime = logon_time_id

if(logoff_time < end_valid_period) finalDatetime = logoff_time else finalDatetime = end_valid_period

Is there anyway I can do this in a query, without using a stored procedure with "ifs" and everything else?

Thank you!

Hi!

Forget one thing! I'm wondering if there is a way of doing it without using the case statement as well!

Thank you!

|||

use datediff

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

the case keyword in sql is very powerful you can use it in the query to replace value

this is a single select statement to solve your problem

select

datediff( mi,

case
when logon_time_id< start_valid_period then start_valid_period
else logon_time_id
end

,-- comma
case
when loggoff_time > end_valid_period then end_valid_period
else loggoff_time
end

)as minutesworked

from mytime

joeydj

|||

use datediff

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

the case keyword in sql is very powerful you can use it in the query to replace value

this is a single select statement to solve your problem

select

datediff( mi,

case
when logon_time_id< start_valid_period then start_valid_period
else logon_time_id
end

,-- comma
case
when loggoff_time > end_valid_period then end_valid_period
else loggoff_time
end

)as minutesworked

from mytime

joeydj

|||

Case would be easiest and clearest, but you could do:

select (select max(dateval)
from (select login_time_id as dateval
union all
select start_valid_period)) as initialDatetime,

(select min(dateval)
from (select logoff_time
union all
select end_valid_period)) as initialDatetime

from ...

|||

The first thing to note when comparing date overlaps is that there are 6 cases -- 4 with overlap and 2 without. Presumably, if the user was logged in only during a period that was not valid, the elapsed time should be zero. Using the logic as listed (ifs and CASEs) you could end up with a negative time accounting.

Now for a trick from the old days, before CASE was available (we always walked uphill barefoot a lot in those days, too ;) ). There is a function called SIGN() that returns -1, 0, or 1 depending on the sign of a number. By coercing it into a binary 1 or 0 and multiplying by it, you can get the same effect as a conditional.

In this case, the problem can be recast as increase the start_valid by the difference with the logon time as long as long as the difference is greater than zero. Similarly, the end_valid should be decreased by the difference of the logoff time as long as that difference is negative. Once these adjustments have been done, now apply the DateDiff().

Here is some code that should do the trick. As noted above, the case of no overlap is handled separately. The CASE statements are only to explain which case is being handled.

Drop Table #timekeeper
go

Create Table #timekeeper(
username varchar(30),
logon_time_id datetime,
loggoff_time datetime,
start_valid_period datetime,
end_valid_period datetime
)

Insert #timekeeper values( 'Fred', '04/07/2006 11:00', '04/07/2006 12:20', '04/07/2006 12:10', '04/07/2006 12:30' )
Insert #timekeeper values( 'Wilma', '04/07/2006 12:20', '04/07/2006 12:40', '04/07/2006 12:10', '04/07/2006 12:30' )
Insert #timekeeper values( 'Barney', '04/07/2006 11:20', '04/07/2006 12:40', '04/07/2006 12:10', '04/07/2006 12:30' )
Insert #timekeeper values( 'Betty', '04/07/2006 12:20', '04/07/2006 12:25', '04/07/2006 12:10', '04/07/2006 12:30' )
Insert #timekeeper values( 'Pebbles', '04/07/2006 11:00', '04/07/2006 11:25', '04/07/2006 12:10', '04/07/2006 12:30' )
Insert #timekeeper values( 'Bambam', '04/07/2006 12:35', '04/07/2006 12:50', '04/07/2006 12:10', '04/07/2006 12:30' )

Select username,
Datediff( mi,
DateAdd( ms, (( 1 + Sign( DateDiff( ms, start_valid_period, logon_time_id ) ) ) / 2) * DateDiff( ms, start_valid_period, logon_time_id ), start_valid_period ),
DateAdd( ms, (( 1 + Sign( DateDiff( ms, loggoff_time, end_valid_period ) ) ) / 2) * DateDiff( ms, end_valid_period, loggoff_time ), end_valid_period )
) as usage_minutes,
'Overlap',
Case when logon_time_id < start_valid_period then 'Logged on early' else 'Logged on during valid' end,
Case when loggoff_time < end_valid_period then 'Logged out early' else 'Logged off after valid' end
From #timekeeper
Where start_valid_period <= loggoff_time
And logon_time_id <= end_valid_period
Union All
Select username,
0,
'No overlap',
Case when logon_time_id > end_valid_period then 'Logon after valid' else '' end,
Case when loggoff_time < start_valid_period then 'Logged off before valid' else '' end
From #timekeeper
Where Not(
start_valid_period <= loggoff_time
And logon_time_id <= end_valid_period
)


Fred 10 Overlap Logged on early Logged out early
Wilma 10 Overlap Logged on during valid Logged off after valid
Barney 20 Overlap Logged on early Logged off after valid
Betty 5 Overlap Logged on during valid Logged out early
Pebbles 0 No overlap Logged off before valid
Bambam 0 No overlap Logon after valid

|||Thank you!!!

How can I choose a query based on Parameter values

I have 3 parameter fields, last-name, middle-name, first-name
and the view/table of database has just one string combined of all
three(and it is NOT possible to split).
I need to provide search facility with any combination of these three
fields.
I am very new to this environs and would like to know how I can
achieve this.
Do I have to create an SP which checks if each of the fields is NULL
and do accordingly ?
any help will be appreciated
Thanks
BofoIf I understand what you want correctly you could do this:
select * from yourtable where name like '%' + @.FirstName + '%' + @.MiddleName
+ '%' + @.LastName + '%'
The above query doesn't care if a parameter is null, or has a space or a
partial first name, partial lastname etc (I don't know if they are putting
in the names freeform or picking from a listbox). Anyway, that should at
least give you an idea.
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<bofobofo@.yahoo.com> wrote in message
news:55950c3f.0501271730.6d87c737@.posting.google.com...
>I have 3 parameter fields, last-name, middle-name, first-name
> and the view/table of database has just one string combined of all
> three(and it is NOT possible to split).
> I need to provide search facility with any combination of these three
> fields.
> I am very new to this environs and would like to know how I can
> achieve this.
> Do I have to create an SP which checks if each of the fields is NULL
> and do accordingly ?
> any help will be appreciated
> Thanks
> Bofo|||Hello Bruce,
Thanks for the advice. I have been trying queries in those lines but I
dont get the results.
I get the result only in the case where the Lastname, Middlename and
Firstname match.
for example
I have tried the following:
Name LIKE '%' + @.last + '%' + @.middle + '%' + @.first + '%' --> only
matches if all strings are provided.
Name LIKE '%' + @.last + '%' + @.first + '%' --> matches all with the
last and first
etc..
I can use an OR to consider all possibilities but when i have to
consider the cases when the user gives a single param i will always get
a bunch of results even when the user gives the fullname
For this reason i would like to know if I can put some PL/SQL logic for
diff cases but seems like that is not the way to go as my query is not
being accepted.
Is there any other way I can do this ? a Stored P ? any ideas how to
do it ?
Thanks very much
bofo|||I go it working. Using a stored procedure.
thanks

How can I check for Null or Empty in an Insert/Select Statement

Is there a way in the following Query to check if the _vocon.COMPANY is
null/empty and if so replace _vocon.Id + 10200000 with null (as shown in
statement 2) as each record is processed. I would like to use something like
IIF( IsNull(_vocon.COMPANY), Null, _vocon.Id + 10200000)
INSERT INTO Contact (ContactID, ContactCode, ContactFormat,Title,
FirstName, MiddleName, LastName, notes, CompanyName, Position, CompanyID,
ContactOwner, CreateDate, CreatedBy, LastChangeDate, LastChangedBy,
LanguageCode, Sex, CurrentBalance, Flag19 ) SELECT _vocon.Id + 10100000,
_vocon.Id + 10100000, 'I', _vocon.TITLE, _vocon.FIRSTNAME,
_vocon.OTHERNAMES, _vocon.LASTNAME, NULL, _vocon.COMPANY, NULL, _vocon.Id +
10200000, 1, '01/08/2003', NULL, '01/08/2003', 0, 1, 'U', 0, 1 FROM _vocon
If the company name is null
INSERT INTO Contact (ContactID, ContactCode, ContactFormat,Title,
FirstName, MiddleName, LastName, notes, CompanyName, Position, CompanyID,
ContactOwner, CreateDate, CreatedBy, LastChangeDate, LastChangedBy,
LanguageCode, Sex, CurrentBalance, Flag19 ) SELECT _vocon.Id + 10100000,
_vocon.Id + 10100000, 'I', _vocon.TITLE, _vocon.FIRSTNAME,
_vocon.OTHERNAMES, _vocon.LASTNAME, NULL, _vocon.COMPANY, NULL, NULL, 1,
'01/08/2003', NULL, '01/08/2003', 0, 1, 'U', 0, 1 FROM _vocon
Regards
Jeff
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.554 / Virus Database: 346 - Release Date: 20/12/2003Hi
You don't give the version of SQLServer, it is also better to post DDL
(Create table statements etc...), example data (as Insert statements) to
avoid ambiguities.
The behaviour of concatenating with null can be set with the
CONCAT_NULL_YIELDS_NULL option see:
mk:@.MSITStore:C:\Program%20Files\Microsoft%20SQL%20Server\80\Tools\Books\tsq
lref.chm::/ts_set-set_2z8s.htm
To update your values you could use:
UPDATE _vocon
SET Company = Id + 10200000
WHERE Company IS NULL
OR LEN(RTRIM(Company)) = 0
John
"Jeff Williams" <jeff.williams@.hardsoft.com.au> wrote in message
news:uqveIhNzDHA.2568@.TK2MSFTNGP09.phx.gbl...
> Is there a way in the following Query to check if the _vocon.COMPANY is
> null/empty and if so replace _vocon.Id + 10200000 with null (as shown in
> statement 2) as each record is processed. I would like to use something
like
> IIF( IsNull(_vocon.COMPANY), Null, _vocon.Id + 10200000)
> INSERT INTO Contact (ContactID, ContactCode, ContactFormat,Title,
> FirstName, MiddleName, LastName, notes, CompanyName, Position, CompanyID,
> ContactOwner, CreateDate, CreatedBy, LastChangeDate, LastChangedBy,
> LanguageCode, Sex, CurrentBalance, Flag19 ) SELECT _vocon.Id + 10100000,
> _vocon.Id + 10100000, 'I', _vocon.TITLE, _vocon.FIRSTNAME,
> _vocon.OTHERNAMES, _vocon.LASTNAME, NULL, _vocon.COMPANY, NULL, _vocon.Id
+
> 10200000, 1, '01/08/2003', NULL, '01/08/2003', 0, 1, 'U', 0, 1 FROM
_vocon
> If the company name is null
> INSERT INTO Contact (ContactID, ContactCode, ContactFormat,Title,
> FirstName, MiddleName, LastName, notes, CompanyName, Position, CompanyID,
> ContactOwner, CreateDate, CreatedBy, LastChangeDate, LastChangedBy,
> LanguageCode, Sex, CurrentBalance, Flag19 ) SELECT _vocon.Id + 10100000,
> _vocon.Id + 10100000, 'I', _vocon.TITLE, _vocon.FIRSTNAME,
> _vocon.OTHERNAMES, _vocon.LASTNAME, NULL, _vocon.COMPANY, NULL, NULL, 1,
> '01/08/2003', NULL, '01/08/2003', 0, 1, 'U', 0, 1 FROM _vocon
> Regards
> Jeff
>
>
> --
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.554 / Virus Database: 346 - Release Date: 20/12/2003
>

How can I change the default Save-As/Save directory

I am new to sql sever management studio express, but a long time query analyzer user. This is a very basic question.

I want to change the default directory in sql server management studio express so that when I go to save a query, it is already pointed to the correct one. Where do I change that?

Thanks,

Nanci

Goto [Tools], [Options], [Query Results]

There you will be able to change the default query results storage location.

|||

I have changed that setting, but it only works for the results of the query, not saving the query itself. Any other suggestions?

Nanci

sql

Monday, March 26, 2012

How can I change the CommandTimeout value?

When I try to execute a query and after 30 seconds the program sends me error :

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Exception Detail: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Source error:

Line 550 Dim myDataSet as Dataset = New DataSet

Line 551 myDataSet = db.ExecuteDataSet(System.Data.CommanType.Text,NewSql) <== Error line

Line 552 i=myDataSet.Tables(0).Rows.Count

In my connection string I set the parameter "Connection Timeout" = 360 but it not works. ( In debug mode the value for db.GetConnection.ConnectionTimeout is the same(360) like the parameter timeout connection.

After many searchs I found the default value for CommandTimeout is 30 secs. Can I change this value ?

Any suggestion will be welcome.

I'm using FrameWork 1.1.

create a SqlCommand object and set the CommandTimeout on that.

Hope it helps

|||

Klaus,

Do you have an example or reference in order to get the code?

Thanks in advance,

Juan Carlos

|||

YesOk. I found the example and the solution for my case is :

Dim myDataSet as Dataset = New DataSet

Dim cmd as DbCommandWrapper = db.GetSqlStringCommandWrapper(NewSql)

cmd.CommandTimeout = 180 (seconds) ==> 0 (zero) in order to wait for ever.

myDataSet = db.ExecuteDataSet(cmdl)

i=myDataSet.Tables(0).Rows.Count

If you want to review more of thishttp://msdn.microsoft.com/msdnmag/issues/05/08/DataPoints/

Klaus, I appreciate a lot your help.

Thanks

sql

How can I change the column width?

I'm creating a C# program in Visual Studio. When I query the sql database, the results are put into a data grid view. However, the column widths are always too small when displayed. I have text that is not shown because the column width is not large enough. I tried going into Sql Server Management Studio Express and trying to modify the size property of the columns, but it won't let me change it (its grayed out). How can I fix this problem?Why would you want changing size on the back end server when you need changing size of your grid cells.
You can provide functionality to popup a full text when grid cell double-clicked.

If you'll change backend column size to accommodate your grid size (which is unheard of) you will just truncate existing data in a database and have part of data instead of full set of data.

To limit number of characters returned from a backend to a front end you can use Substring function.

For more help describe your intentions in more detailed and it would be a wise posting it on .NET forum.

Good Luck.

How can I can rid of rows that have -1.#IND

I have several rows that got imported into floats with the -1.#IND value. I
want to run a query to find out which rows it is but I always get a divide
by zero error.
I tried select * from mytable where mycolumn/1 = 0Try:
DELETE
FROM YourTable
WHERE YourFloatCol < CAST(-9.9999999999999998E+37 AS FLOAT)
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"Joe" <J_no_spam@._no_spam_Fishinbrain.com> wrote in message
news:%23yhdsoDRFHA.2384@.tk2msftngp13.phx.gbl...
> I have several rows that got imported into floats with the -1.#IND value.
I
> want to run a query to find out which rows it is but I always get a divide
> by zero error.
> I tried select * from mytable where mycolumn/1 = 0
>
>|||If I try:
select cast('-1.#IND' as float)
I get:
Server: Msg 8114, Level 16, State 5, Line 2
Error converting data type varchar to float.
What is the value that you want to use to filter the rows?
AMB
"Joe" wrote:

> I have several rows that got imported into floats with the -1.#IND value.
I
> want to run a query to find out which rows it is but I always get a divide
> by zero error.
> I tried select * from mytable where mycolumn/1 = 0
>
>|||"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:386B64F9-2E3C-4D90-BC38-E2DB3BA62478@.microsoft.com...
> If I try:
> select cast('-1.#IND' as float)
> I get:
> Server: Msg 8114, Level 16, State 5, Line 2
> Error converting data type varchar to float.
> What is the value that you want to use to filter the rows?
Alejandro,
I'm not sure how the OP got these values, or why SQL Server accepts
them, but I've had this issue in the past when working with the ATL OLE DB
libraries. If you forget to initialize a float before passing it in, that's
what you end up with (I think it's -infinity). It can be a real nightmare
to deal with... If you cast the values to VARCHAR, they show up as -1.#IND.
And at least in my case, SELECTing them w/o the CAST resulted in QA throwing
an error.
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--|||Adam,
Thanks for the explanation, it is very interesting.
AMB
"Adam Machanic" wrote:

> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in messag
e
> news:386B64F9-2E3C-4D90-BC38-E2DB3BA62478@.microsoft.com...
> Alejandro,
> I'm not sure how the OP got these values, or why SQL Server accepts
> them, but I've had this issue in the past when working with the ATL OLE DB
> libraries. If you forget to initialize a float before passing it in, that
's
> what you end up with (I think it's -infinity). It can be a real nightmare
> to deal with... If you cast the values to VARCHAR, they show up as -1.#IND
.
> And at least in my case, SELECTing them w/o the CAST resulted in QA throwi
ng
> an error.
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
>|||Thanks Adam! In my case the values where NaN's but I was able to correct it
now.
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:ex4sruDRFHA.612@.TK2MSFTNGP14.phx.gbl...
> Try:
>
> DELETE
> FROM YourTable
> WHERE YourFloatCol < CAST(-9.9999999999999998E+37 AS FLOAT)
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.datamanipulation.net
> --
>
> "Joe" <J_no_spam@._no_spam_Fishinbrain.com> wrote in message
> news:%23yhdsoDRFHA.2384@.tk2msftngp13.phx.gbl...
value.
> I
divide
>|||Joe,
In case you or anyone is still reading this thread, see
http://groups.google.co.uk/groups?q...ass+float_field
If you look at the IEEE floating point specification and at
CAST(YourFloatCol as binary(8)), you should be able to come up
with a way to filter these values out based on the binary value.
Steve Kass
Drew University
Joe wrote:

> Thanks Adam! In my case the values where NaN's but I was able to correct i
t
> now.
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:ex4sruDRFHA.612@.TK2MSFTNGP14.phx.gbl...
>
> value.
>
> divide
>
>

Wednesday, March 21, 2012

how can I add InsertCommand in SqlDataSource?

I need to add an 'InsertCommand' to my query via sqldatasource, but i cannot see this option, i only have the 'order', 'where' and 'advanced' option, could you please advice?

Hi,

VB is great :) you can add and you insertcommand in code behind for example:

Private Sub Page_Load(ByVal sender As Object, ByVal e As eventArgs) Handles Page.Load

SqlDataSource1.InsertCommand.Add("Cell_Name", System.CodeType.String, TextBox.Text)

End Sub

Thats it

Hope it helps

------------------------------

Please do not forget to mark as "Answered" the answer which helped you. Thanks

|||

It seems that you want to add an InsertCommand to your SQLDatasource dynamically. Below is the code you can use to create an insert command for an existing sql datasource.

<your sql datasource id>.InsertCommand = "<either your insert query or stored procedure name>"
<your sql datasource id>.InsertCommandType = SqlDataSourceCommandType.StoredProcedure or SqlDataSourceCommandType.Text

You can add the command parameters using <your sql datasource id>.InsertParameters.Add method.

To call the insert method you can to use <your sql datasource id>.Insert().

Hope this will help.

|||

i have tried using this code but the 'SqlDataSource1' and 'System.CodeType' are not recognised; says its not declared.

could you please advice?

|||

Hi,

did you added SqlDataSource control in your aspx page ?

Regards

|||

Yes, and i used the same ID name.

Monday, March 19, 2012

how can build two tabels together with ms sql query

Hello to all,

I have now two tabels ( Ta and Tb). the tabel includes difference attributte. I want to build this two tables together.

I used this query:

select * from Ta where Ta.Id = @.ID union all select * from Tb where Tb.IdOfa = @.ID

but it doesn't work and the following error message comes

"All inquiries in an SQL application, which contain a union operator, must contain directly many expressions in their goal lists "

Can someone help me?

Thanks

best Regards

pinsha

Please post some sample data from each table and the result you are expecting out of your query.|||

Hi Pinsha,

While using Union Operator you must have the equal number of columns in both query.

You have written Select * Query 1 Union Select * Query 2

Please check if the number of columns are same in both the queries. ( I mean in both the tables as they are used in queries )

Satya

|||

satya_tanwar:

Please check if the number of columns are same in both the queries. ( I mean in both the tables as they are used in queries )

And the columns should be ofsimilardatatype.

|||

Off Course Bro...Stick out tongue

Satya

Wednesday, March 7, 2012

How a user can execute SQL code

I am currently using DTS to run a query that spits out a txt file of the
results - works great, BUT... this code will now need to be run on a fairly
regular basis (possibly each Fri or Saturday). Although I am familiar with
coding, I am not familiar with having users interface with this code. My
question is, how can I have a user have the ability from his/her desktop to
click a button in some program and run this code? The Query is to a Project
Server database extracting data to be imported elsewhere. I though of
Access, but I do not believe Access can access mdf. Any ideas of what I can
use (I do not have Oracle).create a DTS package and try to Execute the package
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"Diane" wrote:

> I am currently using DTS to run a query that spits out a txt file of the
> results - works great, BUT... this code will now need to be run on a fairl
y
> regular basis (possibly each Fri or Saturday). Although I am familiar wit
h
> coding, I am not familiar with having users interface with this code. My
> question is, how can I have a user have the ability from his/her desktop t
o
> click a button in some program and run this code? The Query is to a Proje
ct
> Server database extracting data to be imported elsewhere. I though of
> Access, but I do not believe Access can access mdf. Any ideas of what I c
an
> use (I do not have Oracle).|||Since your existing DTS package is working fine, you might consider running
it on the client machine. There are a number of methods to do this. One is
to execute the package using DTSRUN or DTSRUNUI and include the command in a
BAT file for easy user execution. Similarly, you can execute the package
directly from a VBScript or Access application.

> I though of Access, but I do not believe Access can access mdf. Any ideas
> of what I can
> use (I do not have Oracle).
You don't access the SQL Server database files directly in Access. You can
either link needed tables from an ODBC data source or query directly using
ADO in VBA code.
If you don't want to use DTS, you can use virtually any scripting or
programming language that allows you to run a SQL query and create a text
file. The best choice depends on your user interface requirements and
expertise. With Access, you could develop a simple form for any needed
parameters that invokes VBA code to perform the export task.
Hope this helps.
Dan Guzman
SQL Server MVP
"Diane" <Diane@.discussions.microsoft.com> wrote in message
news:E799328F-CD41-49F4-AF04-100A1242F70B@.microsoft.com...
>I am currently using DTS to run a query that spits out a txt file of the
> results - works great, BUT... this code will now need to be run on a
> fairly
> regular basis (possibly each Fri or Saturday). Although I am familiar
> with
> coding, I am not familiar with having users interface with this code. My
> question is, how can I have a user have the ability from his/her desktop
> to
> click a button in some program and run this code? The Query is to a
> Project
> Server database extracting data to be imported elsewhere. I though of
> Access, but I do not believe Access can access mdf. Any ideas of what I
> can
> use (I do not have Oracle).|||Yes- I'm a moron ;-( It didn't dawn on me to just load client tools -
thanks!!!!
"Dan Guzman" wrote:

> Since your existing DTS package is working fine, you might consider runnin
g
> it on the client machine. There are a number of methods to do this. One
is
> to execute the package using DTSRUN or DTSRUNUI and include the command in
a
> BAT file for easy user execution. Similarly, you can execute the package
> directly from a VBScript or Access application.
>
> You don't access the SQL Server database files directly in Access. You ca
n
> either link needed tables from an ODBC data source or query directly using
> ADO in VBA code.
> If you don't want to use DTS, you can use virtually any scripting or
> programming language that allows you to run a SQL query and create a text
> file. The best choice depends on your user interface requirements and
> expertise. With Access, you could develop a simple form for any needed
> parameters that invokes VBA code to perform the export task.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Diane" <Diane@.discussions.microsoft.com> wrote in message
> news:E799328F-CD41-49F4-AF04-100A1242F70B@.microsoft.com...
>
>

How "WHERE" clause can be used in MDX query?

Hi,

I am writing MDX query to retrive a set of data based on selected range of date.

I have written a MDX query but it is not filtering .

My code:

SELECT NON EMPTY { [Measures].[Fact Table Count] } ON COLUMNS, NON EMPTY topcount({ ([Date Time1].[Date Time1].[Date Time1].ALLMEMBERS ) } ,1000)DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( [Date Time1].[Date Time1].&[2006-01-25T05:53:07] : [Date Time1].[Date Time1].&[2006-02-25T15:53:56] ) ON COLUMNS FROM [Cube Analysis]) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

This code should display only data with selected range of date but it displaying all data.

Can any one give a solution to filter the data based on Date using WHERE clause.

Thank you.

The subcube filter looks fine. Can you repro this against the Adventure Works cube?|||

Try this

with member [Measures].[FILTERBYTIME] AS

SUM(

CROSSJOIN(

[Measures].[Fact Table Count],

[Date Time1].[Date Time1].&[2006-01-25T05:53:07] : [Date Time1].[Date Time1].&[2006-02-25T15:53:56]

)

)

SELECT

NON EMPTY { [Measures].[FILTERBYTIME] } ON COLUMNS,

NON EMPTY topcount(

{

([Date Time1].[Date Time1].[Date Time1].ALLMEMBERS )

} ,1000

)DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Cube Analysis] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

or try this one.

SELECT

NON EMPTY

{ [Measures].[Fact Table Count] } ON COLUMNS,

NON EMPTY topcount(

{

([Date Time1].[Date Time1].[Date Time1].ALLMEMBERS )

} ,1000

)DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Cube Analysis]

where

{

[Date Time1].[Date Time1].&[2006-01-25T05:53:07] : [Date Time1].[Date Time1].&[2006-02-25T15:53:56]

}

CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

How "WHERE" clause can be used in MDX query?

Hi,

I am writing MDX query to retrive a set of data based on selected range of date.

I have written a MDX query but it is not filtering .

My code:

SELECT NON EMPTY { [Measures].[Fact Table Count] } ON COLUMNS, NON EMPTY topcount({ ([Date Time1].[Date Time1].[Date Time1].ALLMEMBERS ) } ,1000)DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( [Date Time1].[Date Time1].&[2006-01-25T05:53:07] : [Date Time1].[Date Time1].&[2006-02-25T15:53:56] ) ON COLUMNS FROM [Cube Analysis]) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

This code should display only data with selected range of date but it displaying all data.

Can any one give a solution to filter the data based on Date using WHERE clause.

Thank you.

The subcube filter looks fine. Can you repro this against the Adventure Works cube?|||

Try this

with member [Measures].[FILTERBYTIME] AS

SUM(

CROSSJOIN(

[Measures].[Fact Table Count],

[Date Time1].[Date Time1].&[2006-01-25T05:53:07] : [Date Time1].[Date Time1].&[2006-02-25T15:53:56]

)

)

SELECT

NON EMPTY { [Measures].[FILTERBYTIME] } ON COLUMNS,

NON EMPTY topcount(

{

([Date Time1].[Date Time1].[Date Time1].ALLMEMBERS )

} ,1000

)DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Cube Analysis] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

or try this one.

SELECT

NON EMPTY

{ [Measures].[Fact Table Count] } ON COLUMNS,

NON EMPTY topcount(

{

([Date Time1].[Date Time1].[Date Time1].ALLMEMBERS )

} ,1000

)DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Cube Analysis]

where

{

[Date Time1].[Date Time1].&[2006-01-25T05:53:07] : [Date Time1].[Date Time1].&[2006-02-25T15:53:56]

}

CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

HOW "TOP" is interpreted?

All,
Not any project specific but just a beginner's query put me at
corner.
SELECT TOP 10 * FROM <TABLE_NAME>
Sqlserver2000 returns 10 results, but the question is "these 10 results
are top 10 results" means what? There are 100s columns in the table
with lacks of rows. Among them how this 10 results were ranked'
Any suggestions...?MUKUT (hidevraj@.gmail.com) writes:
> Not any project specific but just a beginner's query put me at
> corner.
> SELECT TOP 10 * FROM <TABLE_NAME>
> Sqlserver2000 returns 10 results, but the question is "these 10 results
> are top 10 results" means what? There are 100s columns in the table
> with lacks of rows. Among them how this 10 results were ranked'
As long as there is on ORDER BY clause, the answer is simply "the rows
that are cheapest for SQL Server to return". Thus, the result is not
deterministic, although it's neither random.
Normally you combine TOP with an ORDER BY in which case the ORDER BY clause
serves to give the TOP clause a deterministic meaning (save for ties, unless
you specify WITH TIES).
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||> SELECT TOP 10 * FROM <TABLE_NAME>
> Sqlserver2000 returns 10 results, but the question is "these 10 results
> are top 10 results" means what? There are 100s columns in the table
> with lacks of rows. Among them how this 10 results were ranked'
Always use ORDER BY with TOP:
SELECT TOP 10 * FROM <TABLE_NAME>
ORDER BY column (ASC / DESC)
Now you know waht top 10 means.
Dejan Sarka, SQL Server MVP
Mentor, www.SolidQualityLearning.com
Anything written in this message represents solely the point of view of the
sender.
This message does not imply endorsement from Solid Quality Learning, and it
does not represent the point of view of Solid Quality Learning or any other
person, company or institution mentioned in this message|||Erland Sommarskog wrote:
> As long as there is on ORDER BY clause, the answer is simply "the rows
> that are cheapest for SQL Server to return". Thus, the result is not
> deterministic, although it's neither random.
> Normally you combine TOP with an ORDER BY in which case the ORDER BY claus
e
> serves to give the TOP clause a deterministic meaning (save for ties, unle
ss
> you specify WITH TIES).
>
Ya, I understood the significance of using ORDER BY with TOP.........
No disrespect at all, but Erland, would you please brief on the
statement
"The result is not deterministic, although it's neither random."
I aware to guess... when there is no ORDER BY.. the results are
expected to be in random order.
And still I am that how sqlserver2000 interprets the
Select TOP 20 * from <TABLE_NAME>...!!!!|||> No disrespect at all, but Erland, would you please brief on the
> statement
> "The result is not deterministic, although it's neither random."
The first part states that you can execute the same query several times and
what rows you are
returned are not guaranteed in any way to be the same rows. The second part
states that SQL Server
doesn't add some random number generator to return rows in a random fashion.

> I aware to guess... when there is no ORDER BY.. the results are
> expected to be in random order.
No, not random. At least of you go by a strict definition of what random mea
n. What happen is that
you ask for, say, 10 rows. Any rows from the table, you don't care which row
s are returned. So, SQL
Server will pick an execution plan which is as cheap as possible to return 1
0 rows. This is why it
isn't deterministic, you can get different execution plans for different exe
cutions.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"MUKUT" <hidevraj@.gmail.com> wrote in message
news:1149766325.373514.173190@.i39g2000cwa.googlegroups.com...
> Erland Sommarskog wrote:
> Ya, I understood the significance of using ORDER BY with TOP.........
> No disrespect at all, but Erland, would you please brief on the
> statement
> "The result is not deterministic, although it's neither random."
> I aware to guess... when there is no ORDER BY.. the results are
> expected to be in random order.
> And still I am that how sqlserver2000 interprets the
> Select TOP 20 * from <TABLE_NAME>...!!!!
>|||> No, not random. At least of you go by a strict definition of what random
> mean. What happen is that you ask for, say, 10 rows. Any rows from the
> table, you don't care which rows are returned. So, SQL Server will pick an
> execution plan which is as cheap as possible to return 10 rows. This is
> why it isn't deterministic, you can get different execution plans for
> different executions.
The main problem is that, since you often get the SAME execution plan,
people think this is the intended behavior, and you will *always* get the
same execution plan. Which, of course, we know is not true. But it still
leaves a lot of people lazy, leaving out the ORDER BY clause, expecting it
to behave the same with or without it. Sorry for those people that have to
search and modify all their procedures with "TOP" when they migrate to SQL
Server 2005, which tends to "break" this behavior more often than not. :-)|||When there is no ORDER BY, the dictionary meaning of TOP is hampered by
the way sqlserver2000 behaves...:):)
Anyway, things are clear to me...thank you all for your time.|||> When there is no ORDER BY, the dictionary meaning of TOP is hampered by
> the way sqlserver2000 behaves...:):)
True. I've always thought they should have named it STOPAFTER...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"MUKUT" <hidevraj@.gmail.com> wrote in message
news:1149827146.025175.234160@.i39g2000cwa.googlegroups.com...
> When there is no ORDER BY, the dictionary meaning of TOP is hampered by
> the way sqlserver2000 behaves...:):)
> Anyway, things are clear to me...thank you all for your time.
>

Friday, February 24, 2012

Hotfix for 826906 in SP4?

Greetings.
Apparently the fix described in article 826906 ("A query that uses a view
that contains a correlated subquery and an aggregate runs slowly") didn't
make it into SP4.
I think I'm getting bitten by this, and don't have an easy way to rewrite
the query (it's generated by Analysis Services). Is there any ETA for a
corresponding hotfix to be released for SP4?
Regards,
JonathanHello,
The final release of this hotfix for SP4 has not been determined. If there
is any update we will let you know.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi Sophie,
Thanks for your reply.
"Sophie Guo [MSFT]" wrote:
> The final release of this hotfix for SP4 has not been determined. If there
> is any update we will let you know.
The knowlege base article for 826906 says that the hotfix will be available
"shortly."
This bug is biting us hard. Can you give me a hint as to what "shortly"
means?
Thanks,
Jonathan|||Hello,
I appologize that we are unable to offer any further information on this
matter. Once the update is released, we will update you as soon as
possible and the article will be update.
I suggest that you unsintall SP4 and reinstall SP3 and the hotfix if the
issue is urgent. For more information about uninstalling SP4, you may refer
to the readme file of the SQL server 2000 SP4.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Do these guys even read this stuff?
Johnathan, how do you know whether or not this fix made it into the SP4
release?
As you know, SQL Server builds are cumulative. The fix you are referring to
is build 8.00.850. The cutoff build for the SP4 Beta was originally set at
8.00.972 and relabled 8.00.2026 to allow additional post-SP3 hotfixes not
included in SP4. The final release for SP4, build 8.00.2039, looks like it
included all fixes up through build 8.00.1007.
Also, here is the published list of fixes for the SP4 build:
A list of the bugs that are fixed in SQL Server 2000 Service Pack 4
http://support.microsoft.com/default.aspx?scid=kb;en-us;888799
If you need it, here is the list of post-SP3 hotfixes:
SQL Server 2000 hotfix update for SQL Server 2000 Service Pack 3 and 3a
http://support.microsoft.com/?kbid=810185
Hope this helps.
Sincerely,
Anthony Thomas
"Sophie Guo [MSFT]" <v-sguo@.online.microsoft.com> wrote in message
news:1%23mFpMfYFHA.3336@.TK2MSFTNGXA01.phx.gbl...
Hello,
I appologize that we are unable to offer any further information on this
matter. Once the update is released, we will update you as soon as
possible and the article will be update.
I suggest that you unsintall SP4 and reinstall SP3 and the hotfix if the
issue is urgent. For more information about uninstalling SP4, you may refer
to the readme file of the SQL server 2000 SP4.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Anthony,
Thanks for your reply.
"Anthony Thomas" wrote:
> Johnathan, how do you know whether or not this fix made it into the SP4
> release?
I'm going by the text of article 826906, which says, in part, "Note This
hotfix is not included with Microsoft SQL Server 2000 Service Pack 4 (SP4).
If you apply this hotfix and then apply SP4, this hotfix will be overwritten.
A hotfix for SP4 will soon be available."
Regards,
Jonathan|||Yep, it sure does say that, but the Fixlist KB shows that it is included;
so, since the KB you are referencing is more recent (by about a week, at
most), I'd have to go with that. However, that is in direct contridiction
with how MS deploys cumulative builds.
The only thing I can conclude from this is that it had been included in the
Beta version but had been removed prior to public release.
So, your choices are to go ahead and deploy SP 4 and wait for the hotfix
they are working on to reinclude it, contact PSS to get the hot fix listed
in this KB, or apply a different, later post-SP3 hotfix that MUST contain
this fix, following MS cumulative build strategy.
The latest publicly available, post-SP3 hotfix is for build 8.00.878 and can
be downloaded here:
You must install the SQL Server 2000 update that KB article 831950 describes
to run BizTalk Server 2004
http://support.microsoft.com/?kbid=838166
For the english version:
http://download.microsoft.com/download/9/0/4/9046652b-2b9b-4d49-98c8-e74ba1849af5/sql2000-kb810185-8.00.0878-enu.exe
This one replaced the last publicly available, post-SP3 hotfix, build
8.00.859 because it had severe bugs in it.
Hope this helps.
Sincerely,
Anthony Thomas
"Jonathan Levine" <myfoo2@.nospam.nospam> wrote in message
news:9ADED83C-EDBE-4811-8881-622AA3C21103@.microsoft.com...
Anthony,
Thanks for your reply.
"Anthony Thomas" wrote:
> Johnathan, how do you know whether or not this fix made it into the SP4
> release?
I'm going by the text of article 826906, which says, in part, "Note This
hotfix is not included with Microsoft SQL Server 2000 Service Pack 4 (SP4).
If you apply this hotfix and then apply SP4, this hotfix will be
overwritten.
A hotfix for SP4 will soon be available."
Regards,
Jonathan|||"Sophie Guo [MSFT]" wrote:
> I appologize that we are unable to offer any further information on this
> matter. Once the update is released, we will update you as soon as
> possible and the article will be update.
Sophie,
It's now been a month since article 826906 was last updated, promising
that a "hotfix for SP4 will soon be available."
Is there any news on when it will be "soon?"
Regards,
Jonathan|||Hello,
The exact ship date is not known as it must await another package being
delivered. Thanks.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi, Sophie. Any news on this one? It's been months now...
Regards,
Jonathan
"Sophie Guo [MSFT]" wrote:
> Hello,
> The exact ship date is not known as it must await another package being
> delivered. Thanks.
> Sophie Guo
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> =====================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>|||Hello,
I read the folloiwng information internally:
This hotfix is scheduled to be included with a post-Service Pack 4 hotfix
rollup package and with SQL Server 2000 Service Pack 5.
If the issue is urgent, please contact Customer Service and Support (CSS)
for immediate assistance. For more information on available CSS services,
please click here:
http://support.microsoft.com/default.aspx?scid=fh;EN-US;OfferProPhone#faq607
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/default.aspx?scid=%2finternational.aspx.
NOTE: In special cases, charges that are ordinarily incurred for support
calls may be canceled if a Microsoft Support Professional determines that a
specific update will resolve your problem. The typical support costs will
apply to additional support questions and issues that do not qualify for
the specific update in question.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Sophie, thanks for your reply.
"Sophie Guo [MSFT]" wrote:
> This hotfix is scheduled to be included with a post-Service Pack 4 hotfix
> rollup package and with SQL Server 2000 Service Pack 5.
> If the issue is urgent, please contact Customer Service and Support (CSS)
> for immediate assistance. For more information on available CSS services,
> please click here:
I'm not sure what this means. Does it mean:
1. There's a hotfix I can get now?
Or
2. The fix is available but hasn't been packaged yet, and won't be
packaged unless enough people call and complain?
Or
3. The fix is not yet available?
Or
4. Something else?
Thanks,|||Hello,
The hotfix for SP4 is still unavailable now. However, if the issue is
urgent, CSS will investigate this issue at the urgent level and might
provide a hot fix for you. Thanks.
Sophie Guo
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.

Sunday, February 19, 2012

Hosting an SQL database on remote share

Hi,
I would really appreciate help with this query.

I have an SQL 2000 server setup with 2 databases. My boss would like to setup another database but wants the actual database to reside on a different server share.

Is is possible for one database on an SQL server to be hosted on a remote share ?

appreicate any info
thanksIt can be done, but it is difficult, complex, and unsupported. I wouldn't go there, the risk is way too high.

-PatP|||Main point to think about is Performance and is there any reason why your boss is thinking in such a high-fly idea.