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

Friday, March 30, 2012

Named Query on tables in separate dbs?

Is it possible to write a named query on tables in different databases?Sure, just use your standard TSQL syntax..

Select
A.field1,B.field2
from DB1.user.tablename A inner join DB2.user.tablename B
on A.ID = B.ID

C|||Actually I do not want to hard code the database name in the query. Can I use the datasources somehow?|||I have not been able to query across datasources.

If you just want to query one db, then you could create a view in one db that queries both dbs.

Named query not appearing in report builder

I'm having a heck of a time with named queries. At this point I just want a proof of concept in my DSV. I have a bunch of tables added to the DSV, and I would like to add a named query to it so the user can pick from the name query in report builder. What has to be done to make it appear in the report builder?

Nevermind. I didn't realize that the report model definition had to be refreshed.

Named query as a pivot

Hello,

Is it possible to create a named query in the DSV that is the result of a pivot (e.g. cross tab?). The number of columns as a result of the pivot are based the number of records in one of the driving tables - in other words, it is not fixed.

You got to go dynamic SQL and use some fancy report datasets and expressions to display or not the columns.

Then you would have to create a report were you define as many columns as possible and control the visibility of these columns based on some expression stored in the Column Visibity hidden property.

Lot of work. May be you would be better off sourcing your report out of a cube.

Philippe

Named query as a pivot

Hello,

Is it possible to create a named query in the DSV that is the result of a pivot (e.g. cross tab?). The number of columns as a result of the pivot are based the number of records in one of the driving tables - in other words, it is not fixed.

You got to go dynamic SQL and use some fancy report datasets and expressions to display or not the columns.

Then you would have to create a report were you define as many columns as possible and control the visibility of these columns based on some expression stored in the Column Visibity hidden property.

Lot of work. May be you would be better off sourcing your report out of a cube.

Philippe

Named Query and Global Variables

Hello,
I want to filter records right in the Data Source View.
I did a "Replace Table with new Named Query" but how can I get it to filter
records by User!UserID?
Thanks,
-Will"I want to filter records right in the Data Source View."
What do you mean by this?
you want to filter your DATA? or do you want to set different
permissions for different users?|||I want to filter my data.
So "select * from table where field1=user!userid"
"sorcerdon@.gmail.com" wrote:
> "I want to filter records right in the Data Source View."
> What do you mean by this?
> you want to filter your DATA? or do you want to set different
> permissions for different users?
>|||Query parameters do not have to map to report parameters. RS automatically
creates a report parameter for every query parameter but you can delete them
and use an expression.
So, do this:
select * from mytable where field1 = @.User
RS will create automatically a report parameter called User. Instead of
using this mapping, you want to change it.
Click on the ... in the dataset designer, go to the parameters tab. On the
right side change from using a report parameter to using an expression. This
will bring you to the expression builder where you can set it to =User!UserID
Now, in the layout tab, report parameters menu, delete the report parameter
which was created for you.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"WillG" <WillG@.discussions.microsoft.com> wrote in message
news:4DBBDA27-67CC-4873-97EF-38B90C1D1E9B@.microsoft.com...
>I want to filter my data.
> So "select * from table where field1=user!userid"
>
> "sorcerdon@.gmail.com" wrote:
>> "I want to filter records right in the Data Source View."
>> What do you mean by this?
>> you want to filter your DATA? or do you want to set different
>> permissions for different users?
>>|||I'm trying to use report models though.
So f I follow the example from msdn here:
http://msdn2.microsoft.com/en-us/library/ms156284.aspx
So after I create "Data Source View" I click on a Product table and click
replace with a named query, this let's me edit the sql or use the query
builder to filter records. In the "Filer" column for a field called user_id I
put =User!UserID, hoping that only products that user_id = User!UserId will
be returned. It does not like that filter, in fact I see nothing about global
variables or variables at all.
**The above is the way I'd like to do my filtering, but if not then:
I tried filtering in the "Report Model":
Looked at the fields, click "Add Group" and All must contain
dragged the user_id field into that "All must contain" box and set it to
user_id must contain GetUserID()
Not sure about the exact area's I clicked because I'm not by my development
pc. But I could not get the Report Model to Filter either.
I like the DataSource View filter because it's a universal way for anyone
who creates reports, in reportbuilder or dev. studio, to only have access to
records that have their userid.
-Will
.
"Bruce L-C [MVP]" wrote:
> Query parameters do not have to map to report parameters. RS automatically
> creates a report parameter for every query parameter but you can delete them
> and use an expression.
> So, do this:
> select * from mytable where field1 = @.User
> RS will create automatically a report parameter called User. Instead of
> using this mapping, you want to change it.
> Click on the ... in the dataset designer, go to the parameters tab. On the
> right side change from using a report parameter to using an expression. This
> will bring you to the expression builder where you can set it to => User!UserID
> Now, in the layout tab, report parameters menu, delete the report parameter
> which was created for you.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "WillG" <WillG@.discussions.microsoft.com> wrote in message
> news:4DBBDA27-67CC-4873-97EF-38B90C1D1E9B@.microsoft.com...
> >I want to filter my data.
> > So "select * from table where field1=user!userid"
> >
> >
> > "sorcerdon@.gmail.com" wrote:
> >
> >> "I want to filter records right in the Data Source View."
> >>
> >> What do you mean by this?
> >>
> >> you want to filter your DATA? or do you want to set different
> >> permissions for different users?
> >>
> >>
>
>|||Sorry, I don't have any experience with report models. Can't help you.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"WillG" <WillG@.discussions.microsoft.com> wrote in message
news:E1041A66-B463-4011-9EF6-0C0D11BF2E12@.microsoft.com...
> I'm trying to use report models though.
> So f I follow the example from msdn here:
> http://msdn2.microsoft.com/en-us/library/ms156284.aspx
> So after I create "Data Source View" I click on a Product table and click
> replace with a named query, this let's me edit the sql or use the query
> builder to filter records. In the "Filer" column for a field called
> user_id I
> put =User!UserID, hoping that only products that user_id = User!UserId
> will
> be returned. It does not like that filter, in fact I see nothing about
> global
> variables or variables at all.
> **The above is the way I'd like to do my filtering, but if not then:
> I tried filtering in the "Report Model":
> Looked at the fields, click "Add Group" and All must contain
> dragged the user_id field into that "All must contain" box and set it to
> user_id must contain GetUserID()
> Not sure about the exact area's I clicked because I'm not by my
> development
> pc. But I could not get the Report Model to Filter either.
> I like the DataSource View filter because it's a universal way for anyone
> who creates reports, in reportbuilder or dev. studio, to only have access
> to
> records that have their userid.
> -Will
>
> .
> "Bruce L-C [MVP]" wrote:
>> Query parameters do not have to map to report parameters. RS
>> automatically
>> creates a report parameter for every query parameter but you can delete
>> them
>> and use an expression.
>> So, do this:
>> select * from mytable where field1 = @.User
>> RS will create automatically a report parameter called User. Instead of
>> using this mapping, you want to change it.
>> Click on the ... in the dataset designer, go to the parameters tab. On
>> the
>> right side change from using a report parameter to using an expression.
>> This
>> will bring you to the expression builder where you can set it to =>> User!UserID
>> Now, in the layout tab, report parameters menu, delete the report
>> parameter
>> which was created for you.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "WillG" <WillG@.discussions.microsoft.com> wrote in message
>> news:4DBBDA27-67CC-4873-97EF-38B90C1D1E9B@.microsoft.com...
>> >I want to filter my data.
>> > So "select * from table where field1=user!userid"
>> >
>> >
>> > "sorcerdon@.gmail.com" wrote:
>> >
>> >> "I want to filter records right in the Data Source View."
>> >>
>> >> What do you mean by this?
>> >>
>> >> you want to filter your DATA? or do you want to set different
>> >> permissions for different users?
>> >>
>> >>
>>sql

Monday, March 26, 2012

Named Instance timeout problem

I am running two large applications on a 4 cpu SQL server with 2 named insta
nces.
There are times when I am running a query on one named instance that users o
n the other instance are getting time out errors. I am trying to justify gi
ving each instance limits on which cpu's they can use and also potentially m
emory. I tried giving the
more critical application 3 cpu's and the other one cpu. There was still a
similar problem on the critical app when running a intensive query on the ot
her which was just allocated one cpu. My boss insisted that I change both b
ack to sharing all cpu's.
My argument is that if both can hog all 4 cpu's, I can guarantee that there
will be a problem.
When the large queries are running, the HD lights are on constant and the CP
U's are all pegged at 100%. The databases for each application are stored o
n their own mirrored HD.
I was wondering if anyone out there has experienced a similar problem and wo
ndering where to go from here.
Thank You,
EverettWe went with defaults when the instance was installed. I think both are
dynamic.
"Vikram Jayaram [MS]" wrote:

> What about memory allocation? Are both instnaces alloted to have Dynamic
> Memory? In that case one instnace could be hogging system memory and not
> granting the other enough, on time.
> Vikram Jayaram
> Microsoft, SQL Server
> This posting is provided "AS IS" with no warranties, and confers no rights
.
> Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.
>
>|||Right then., Try alloting one of those to fixed memory of a lesser amount
and see if the behaviour still exists. Worth a try!
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.

Named Instance timeout problem

I am running two large applications on a 4 cpu SQL server with 2 named instances.
There are times when I am running a query on one named instance that users on the other instance are getting time out errors. I am trying to justify giving each instance limits on which cpu's they can use and also potentially memory. I tried giving the
more critical application 3 cpu's and the other one cpu. There was still a similar problem on the critical app when running a intensive query on the other which was just allocated one cpu. My boss insisted that I change both back to sharing all cpu's.
My argument is that if both can hog all 4 cpu's, I can guarantee that there will be a problem.
When the large queries are running, the HD lights are on constant and the CPU's are all pegged at 100%. The databases for each application are stored on their own mirrored HD.
I was wondering if anyone out there has experienced a similar problem and wondering where to go from here.
Thank You,
Everett
We went with defaults when the instance was installed. I think both are
dynamic.
"Vikram Jayaram [MS]" wrote:

> What about memory allocation? Are both instnaces alloted to have Dynamic
> Memory? In that case one instnace could be hogging system memory and not
> granting the other enough, on time.
> Vikram Jayaram
> Microsoft, SQL Server
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.
>
>
|||Right then., Try alloting one of those to fixed memory of a lesser amount
and see if the behaviour still exists. Worth a try!
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.

Friday, March 23, 2012

Named and UnNamed parameters

While creating a report i am running into a problem with parameters.
When building the query i would like to use the same parameter more then
once.
for instance :
select *
from table
where field = @.parameter1
and field = @.Parameter1
and field = @.parameter1
I can runs this Query successfully in the Data tab of the report .however
when i go to the layout or preview tab i get the following error:
The data extension ODBC does not support named parameters. use unnamed
parameters instead.
If i run the query using ? as the parameter i dont have any problems.However
for each ? parameter the user is prompted to supply a value.This is
unacceptable as the user would have to enter the same value numerous times.
select *
from table
where field = ?
and field = ?
and field = ?
Any help would be appreciated.
TIA,
VinnyThere are query parameters and report parameters. RS automatically creates
the report parameters for you. It will create a report parameter for each
unnammed parameter. What you need to do is map each query parameter to a
single report parameter. In the data tab click on the ..., parameters tab.
Map each ? on the left to the same report parameter on the right. Next go to
the layout, report->report parameters and remove the extra unused report
parameters.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Vinny Vinn" <VinnyVinn@.discussions.microsoft.com> wrote in message
news:2F9A3C8B-72DA-4CAD-BE4B-5D4D07CB1C4F@.microsoft.com...
> While creating a report i am running into a problem with parameters.
> When building the query i would like to use the same parameter more then
> once.
> for instance :
> select *
> from table
> where field = @.parameter1
> and field = @.Parameter1
> and field = @.parameter1
> I can runs this Query successfully in the Data tab of the report .however
> when i go to the layout or preview tab i get the following error:
> The data extension ODBC does not support named parameters. use unnamed
> parameters instead.
> If i run the query using ? as the parameter i dont have any
> problems.However
> for each ? parameter the user is prompted to supply a value.This is
> unacceptable as the user would have to enter the same value numerous
> times.
> select *
> from table
> where field = ?
> and field = ?
> and field = ?
> Any help would be appreciated.
> TIA,
> Vinny|||Thank you ,that what i needed.
"Bruce L-C [MVP]" wrote:
> There are query parameters and report parameters. RS automatically creates
> the report parameters for you. It will create a report parameter for each
> unnammed parameter. What you need to do is map each query parameter to a
> single report parameter. In the data tab click on the ..., parameters tab.
> Map each ? on the left to the same report parameter on the right. Next go to
> the layout, report->report parameters and remove the extra unused report
> parameters.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Vinny Vinn" <VinnyVinn@.discussions.microsoft.com> wrote in message
> news:2F9A3C8B-72DA-4CAD-BE4B-5D4D07CB1C4F@.microsoft.com...
> > While creating a report i am running into a problem with parameters.
> > When building the query i would like to use the same parameter more then
> > once.
> > for instance :
> >
> > select *
> > from table
> > where field = @.parameter1
> > and field = @.Parameter1
> > and field = @.parameter1
> >
> > I can runs this Query successfully in the Data tab of the report .however
> > when i go to the layout or preview tab i get the following error:
> > The data extension ODBC does not support named parameters. use unnamed
> > parameters instead.
> >
> > If i run the query using ? as the parameter i dont have any
> > problems.However
> > for each ? parameter the user is prompted to supply a value.This is
> > unacceptable as the user would have to enter the same value numerous
> > times.
> >
> > select *
> > from table
> > where field = ?
> > and field = ?
> > and field = ?
> >
> > Any help would be appreciated.
> >
> > TIA,
> > Vinny
>
>|||Bruce,
I am using DB2 so I also have to use unnamed parms in my queries. I have
used your solution for parms that need entries on the report. However - that
doesnt solve the problem that the query on the data tab still has 10 question
marks in it and it would be really helpful to those that have to modify
"others" reports to not have to try and play "match the parameter" ... Is
there a way to place a comment in the query tab? that might be helpful
enough. Thanks! I am posting a much larger ISSUE about dealing with parms
syntax when I need to code the sql as an expression ... please see Parm
Syntax for SQL Expression
"Bruce L-C [MVP]" wrote:
> There are query parameters and report parameters. RS automatically creates
> the report parameters for you. It will create a report parameter for each
> unnammed parameter. What you need to do is map each query parameter to a
> single report parameter. In the data tab click on the ..., parameters tab.
> Map each ? on the left to the same report parameter on the right. Next go to
> the layout, report->report parameters and remove the extra unused report
> parameters.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Vinny Vinn" <VinnyVinn@.discussions.microsoft.com> wrote in message
> news:2F9A3C8B-72DA-4CAD-BE4B-5D4D07CB1C4F@.microsoft.com...
> > While creating a report i am running into a problem with parameters.
> > When building the query i would like to use the same parameter more then
> > once.
> > for instance :
> >
> > select *
> > from table
> > where field = @.parameter1
> > and field = @.Parameter1
> > and field = @.parameter1
> >
> > I can runs this Query successfully in the Data tab of the report .however
> > when i go to the layout or preview tab i get the following error:
> > The data extension ODBC does not support named parameters. use unnamed
> > parameters instead.
> >
> > If i run the query using ? as the parameter i dont have any
> > problems.However
> > for each ? parameter the user is prompted to supply a value.This is
> > unacceptable as the user would have to enter the same value numerous
> > times.
> >
> > select *
> > from table
> > where field = ?
> > and field = ?
> > and field = ?
> >
> > Any help would be appreciated.
> >
> > TIA,
> > Vinny
>
>

name of the variable (228 row(s) affected)

hello,
after executing a insert in the query anlayser i get a info like (228 row(s)
affected)
How can i acces this value. Is there a internal variablename @.@....
I want to use this value for writing it in a logtable...
Is there any overview of the internal variables which can be used ...
thanks> How can i acces this value. Is there a internal variablename @.@....
Use @.@.ROWCOUNT. A good practice is to save the value in a local variable
for subsequent use.

> Is there any overview of the internal variables which can be used ...
See 'System Functions' in the Books Online for a list of these scalar
functions.
Hope this helps.
Dan Guzman
SQL Server MVP
"Xavier" <Xavier@.discussions.microsoft.com> wrote in message
news:086F2B36-0CE9-460D-BA39-5D7633B4F286@.microsoft.com...
> hello,
> after executing a insert in the query anlayser i get a info like (228
> row(s)
> affected)
> How can i acces this value. Is there a internal variablename @.@....
> I want to use this value for writing it in a logtable...
> Is there any overview of the internal variables which can be used ...
> thanks|||SELECT @.@.ROWCOUNT;
Only available in the very next statement.
"Xavier" <Xavier@.discussions.microsoft.com> wrote in message
news:086F2B36-0CE9-460D-BA39-5D7633B4F286@.microsoft.com...
> hello,
> after executing a insert in the query anlayser i get a info like (228
> row(s)
> affected)
> How can i acces this value. Is there a internal variablename @.@....
> I want to use this value for writing it in a logtable...
> Is there any overview of the internal variables which can be used ...
> thanks|||thanks
Xavier
"Dan Guzman" wrote:

> Use @.@.ROWCOUNT. A good practice is to save the value in a local variable
> for subsequent use.
>
> See 'System Functions' in the Books Online for a list of these scalar
> functions.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Xavier" <Xavier@.discussions.microsoft.com> wrote in message
> news:086F2B36-0CE9-460D-BA39-5D7633B4F286@.microsoft.com...
>
>

Wednesday, March 21, 2012

Name Lookup of Enterprise Manager

Hello!
I have noticed a strange behaviour of Enterprise Manager (or every
program to connect to SQL Server; as in Visual Studio, Query Analyser
and ODBC-Connection Manager), which I cannot get sorted out.
I try to connect to an MSDE-Instance on a clients' Server. The Server
has, for our Maintenance, a dial-up connection with dynamic IP and
runs a service to keep the IP up-to-date, so we can access it by
servername.dyndns.org.
I can ping the server and I can connect to it in pcAnywhere (using the
dyndns.org lookup).
If I try to connect to the MSDE as servername.dyndns.org\Instance, I
get an error: Server not found: Connection.Open(Connect()).
Trying to make an ODBC-Connection gives some numbers on the error:
SQLState: 01000
Server Error: 11004
followed by
SQLState: 08001
Server Error: 6
I can connect to MSDE by using the IP a ping gave me,
1.2.3.4\Instance.
Username and Password must be correct, because a connection with
IP\Instance works fine for the IP looked up a second ago. So my
Question is: Why does Name-Lookup work for ping, work for pcAnywhere,
but not for sql server?
I wonder if someone can give a hint on that on... looking Google
Groups and Knowledge base for the last 2 hours wasn't helpful...
Thanks!Sorry, but since nobody answered, and I really need a little help
here, I *bumped* this one up again.

> Hello!
> I have noticed a strange behaviour of Enterprise Manager (or every
> program to connect to SQL Server; as in Visual Studio, Query Analyser
> and ODBC-Connection Manager), which I cannot get sorted out.
> I try to connect to an MSDE-Instance on a clients' Server. The Server
> has, for our Maintenance, a dial-up connection with dynamic IP and
> runs a service to keep the IP up-to-date, so we can access it by
> servername.dyndns.org.
> I can ping the server and I can connect to it in pcAnywhere (using the
> dyndns.org lookup).
> If I try to connect to the MSDE as servername.dyndns.org\Instance, I
> get an error: Server not found: Connection.Open(Connect()).
> Trying to make an ODBC-Connection gives some numbers on the error:
> SQLState: 01000
> Server Error: 11004
> followed by
> SQLState: 08001
> Server Error: 6
> I can connect to MSDE by using the IP a ping gave me,
> 1.2.3.4\Instance.
> Username and Password must be correct, because a connection with
> IP\Instance works fine for the IP looked up a second ago. So my
> Question is: Why does Name-Lookup work for ping, work for pcAnywhere,
> but not for sql server?
> I wonder if someone can give a hint on that on... looking Google
> Groups and Knowledge base for the last 2 hours wasn't helpful...
> Thanks!

n/w issues and had to reboot.

Has anyone sees issues where although the exec plans are the same , theres
no blocking, and identical hardware that the query would perform slower at
times to return the results to the client whereas it runs much faster when
run on the same box. The query return a few million rows.. It takes as long
as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
results on the client.
Even stopping and starting SQL doesnt work. I just have to reboot and then
its all fast again. I am thinking its being choked someplace.
I have seen this same behaviour on another server as well. and only a reboot
would work. No messages in the log, nothing..
A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
Try sp_updatestats
I had simillar problem, VB6 client ran very slow sometimes, but the same
query (meanwhile!) ran fast in QA.
tv
Hassan napsal(a):
> Has anyone sees issues where although the exec plans are the same , theres
> no blocking, and identical hardware that the query would perform slower at
> times to return the results to the client whereas it runs much faster when
> run on the same box. The query return a few million rows.. It takes as long
> as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
> results on the client.
> Even stopping and starting SQL doesnt work. I just have to reboot and then
> its all fast again. I am thinking its being choked someplace.
> I have seen this same behaviour on another server as well. and only a reboot
> would work. No messages in the log, nothing..
> A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
>
>
|||Have your done profiling and perf-mon'ing of the boxes during these phases?
What are your cache hit ratio's like? Are you suffereing from disk IO queue's
going excessive? Are you having excessive paging? What does CPU utilization
look like?
When it takes 5 minutes, is it after a few iterations (i.e. data has been
cached by previous runs), etc.
"Hassan" wrote:

> Has anyone sees issues where although the exec plans are the same , theres
> no blocking, and identical hardware that the query would perform slower at
> times to return the results to the client whereas it runs much faster when
> run on the same box. The query return a few million rows.. It takes as long
> as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
> results on the client.
> Even stopping and starting SQL doesnt work. I just have to reboot and then
> its all fast again. I am thinking its being choked someplace.
> I have seen this same behaviour on another server as well. and only a reboot
> would work. No messages in the log, nothing..
> A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
>
>
|||Even a restart of SQL Service wont help.. But a reboot of a server sure
does fix it
"Wanderer" <Wanderer@.discussions.microsoft.com> wrote in message
news:957C21BB-A9EE-4E33-8903-205053E55821@.microsoft.com...
> Have your done profiling and perf-mon'ing of the boxes during these
phases?
> What are your cache hit ratio's like? Are you suffereing from disk IO
queue's
> going excessive? Are you having excessive paging? What does CPU
utilization[vbcol=seagreen]
> look like?
> When it takes 5 minutes, is it after a few iterations (i.e. data has been
> cached by previous runs), etc.
> "Hassan" wrote:
theres[vbcol=seagreen]
at[vbcol=seagreen]
when[vbcol=seagreen]
long[vbcol=seagreen]
these[vbcol=seagreen]
then[vbcol=seagreen]
reboot[vbcol=seagreen]

n/w issues and had to reboot.

Has anyone sees issues where although the exec plans are the same , theres
no blocking, and identical hardware that the query would perform slower at
times to return the results to the client whereas it runs much faster when
run on the same box. The query return a few million rows.. It takes as long
as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
results on the client.
Even stopping and starting SQL doesnt work. I just have to reboot and then
its all fast again. I am thinking its being choked someplace.
I have seen this same behaviour on another server as well. and only a reboot
would work. No messages in the log, nothing..
A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003Try sp_updatestats
I had simillar problem, VB6 client ran very slow sometimes, but the same
query (meanwhile!) ran fast in QA.
tv
Hassan napsal(a):
> Has anyone sees issues where although the exec plans are the same , theres
> no blocking, and identical hardware that the query would perform slower at
> times to return the results to the client whereas it runs much faster when
> run on the same box. The query return a few million rows.. It takes as lon
g
> as 1 hr when its slow and as fast as 5 mins when its normal to obtain thes
e
> results on the client.
> Even stopping and starting SQL doesnt work. I just have to reboot and then
> its all fast again. I am thinking its being choked someplace.
> I have seen this same behaviour on another server as well. and only a rebo
ot
> would work. No messages in the log, nothing..
> A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
>
>|||Have your done profiling and perf-mon'ing of the boxes during these phases?
What are your cache hit ratio's like? Are you suffereing from disk IO queue'
s
going excessive? Are you having excessive paging? What does CPU utilization
look like?
When it takes 5 minutes, is it after a few iterations (i.e. data has been
cached by previous runs), etc.
"Hassan" wrote:

> Has anyone sees issues where although the exec plans are the same , theres
> no blocking, and identical hardware that the query would perform slower at
> times to return the results to the client whereas it runs much faster when
> run on the same box. The query return a few million rows.. It takes as lon
g
> as 1 hr when its slow and as fast as 5 mins when its normal to obtain thes
e
> results on the client.
> Even stopping and starting SQL doesnt work. I just have to reboot and then
> its all fast again. I am thinking its being choked someplace.
> I have seen this same behaviour on another server as well. and only a rebo
ot
> would work. No messages in the log, nothing..
> A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
>
>|||Even a restart of SQL Service wont help.. But a reboot of a server sure
does fix it
"Wanderer" <Wanderer@.discussions.microsoft.com> wrote in message
news:957C21BB-A9EE-4E33-8903-205053E55821@.microsoft.com...
> Have your done profiling and perf-mon'ing of the boxes during these
phases?
> What are your cache hit ratio's like? Are you suffereing from disk IO
queue's
> going excessive? Are you having excessive paging? What does CPU
utilization[vbcol=seagreen]
> look like?
> When it takes 5 minutes, is it after a few iterations (i.e. data has been
> cached by previous runs), etc.
> "Hassan" wrote:
>
theres[vbcol=seagreen]
at[vbcol=seagreen]
when[vbcol=seagreen]
long[vbcol=seagreen]
these[vbcol=seagreen]
then[vbcol=seagreen]
reboot[vbcol=seagreen]

n/w issues and had to reboot.

Has anyone sees issues where although the exec plans are the same , theres
no blocking, and identical hardware that the query would perform slower at
times to return the results to the client whereas it runs much faster when
run on the same box. The query return a few million rows.. It takes as long
as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
results on the client.
Even stopping and starting SQL doesnt work. I just have to reboot and then
its all fast again. I am thinking its being choked someplace.
I have seen this same behaviour on another server as well. and only a reboot
would work. No messages in the log, nothing..
A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003Try sp_updatestats
I had simillar problem, VB6 client ran very slow sometimes, but the same
query (meanwhile!) ran fast in QA.
tv
Hassan napsal(a):
> Has anyone sees issues where although the exec plans are the same , theres
> no blocking, and identical hardware that the query would perform slower at
> times to return the results to the client whereas it runs much faster when
> run on the same box. The query return a few million rows.. It takes as long
> as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
> results on the client.
> Even stopping and starting SQL doesnt work. I just have to reboot and then
> its all fast again. I am thinking its being choked someplace.
> I have seen this same behaviour on another server as well. and only a reboot
> would work. No messages in the log, nothing..
> A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
>
>|||Have your done profiling and perf-mon'ing of the boxes during these phases?
What are your cache hit ratio's like? Are you suffereing from disk IO queue's
going excessive? Are you having excessive paging? What does CPU utilization
look like?
When it takes 5 minutes, is it after a few iterations (i.e. data has been
cached by previous runs), etc.
"Hassan" wrote:
> Has anyone sees issues where although the exec plans are the same , theres
> no blocking, and identical hardware that the query would perform slower at
> times to return the results to the client whereas it runs much faster when
> run on the same box. The query return a few million rows.. It takes as long
> as 1 hr when its slow and as fast as 5 mins when its normal to obtain these
> results on the client.
> Even stopping and starting SQL doesnt work. I just have to reboot and then
> its all fast again. I am thinking its being choked someplace.
> I have seen this same behaviour on another server as well. and only a reboot
> would work. No messages in the log, nothing..
> A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
>
>|||Even a restart of SQL Service wont help.. But a reboot of a server sure
does fix it
"Wanderer" <Wanderer@.discussions.microsoft.com> wrote in message
news:957C21BB-A9EE-4E33-8903-205053E55821@.microsoft.com...
> Have your done profiling and perf-mon'ing of the boxes during these
phases?
> What are your cache hit ratio's like? Are you suffereing from disk IO
queue's
> going excessive? Are you having excessive paging? What does CPU
utilization
> look like?
> When it takes 5 minutes, is it after a few iterations (i.e. data has been
> cached by previous runs), etc.
> "Hassan" wrote:
> > Has anyone sees issues where although the exec plans are the same ,
theres
> > no blocking, and identical hardware that the query would perform slower
at
> > times to return the results to the client whereas it runs much faster
when
> > run on the same box. The query return a few million rows.. It takes as
long
> > as 1 hr when its slow and as fast as 5 mins when its normal to obtain
these
> > results on the client.
> >
> > Even stopping and starting SQL doesnt work. I just have to reboot and
then
> > its all fast again. I am thinking its being choked someplace.
> > I have seen this same behaviour on another server as well. and only a
reboot
> > would work. No messages in the log, nothing..
> >
> > A reboot always solves it. Any idea why.. Using SQL 2000 on Windows 2003
> >
> >
> >
> >sql

N' in criteria ?

Hi,
I have new in SQL server. I am using Access for quite a bit. When I
put the value under Criteria column, in query, It puts N' before the
value, what's that mean ' Why they have to do it ?
Thanks
GinolaThe N denotes that the string is Unicode.
Andrew J. Kelly SQL MVP
"Ginola" <ginola@.mailcity.om> wrote in message
news:40020c51.6962015@.msnews.microsoft.com...
quote:

> Hi,
> I have new in SQL server. I am using Access for quite a bit. When I
> put the value under Criteria column, in query, It puts N' before the
> value, what's that mean ' Why they have to do it ?
> Thanks
>
> --
> Ginola
|||N indicates that the string after it is a Unicode string. Use N prefix, only
when comparing a value against a Unicode column, otherwise you will see
performance degradation, as an index may not be used.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Ginola" <ginola@.mailcity.om> wrote in message
news:40020c51.6962015@.msnews.microsoft.com...
Hi,
I have new in SQL server. I am using Access for quite a bit. When I
put the value under Criteria column, in query, It puts N' before the
value, what's that mean ' Why they have to do it ?
Thanks
Ginola|||thanks all for helping.
On Mon, 12 Jan 2004 10:52:06 -0000, "Narayana Vyas Kondreddi"
<answer_me@.hotmail.com> wrote:
quote:

>N indicates that the string after it is a Unicode string. Use N prefix, onl
y
>when comparing a value against a Unicode column, otherwise you will see
>performance degradation, as an index may not be used.

Ginola

Monday, March 19, 2012

N' in criteria ?

Hi,
I have new in SQL server. I am using Access for quite a bit. When I
put the value under Criteria column, in query, It puts N' before the
value, what's that mean ' Why they have to do it ?
Thanks
--
GinolaThe N denotes that the string is Unicode.
--
Andrew J. Kelly SQL MVP
"Ginola" <ginola@.mailcity.om> wrote in message
news:40020c51.6962015@.msnews.microsoft.com...
> Hi,
> I have new in SQL server. I am using Access for quite a bit. When I
> put the value under Criteria column, in query, It puts N' before the
> value, what's that mean ' Why they have to do it ?
> Thanks
>
> --
> Ginola|||N indicates that the string after it is a Unicode string. Use N prefix, only
when comparing a value against a Unicode column, otherwise you will see
performance degradation, as an index may not be used.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Ginola" <ginola@.mailcity.om> wrote in message
news:40020c51.6962015@.msnews.microsoft.com...
Hi,
I have new in SQL server. I am using Access for quite a bit. When I
put the value under Criteria column, in query, It puts N' before the
value, what's that mean ' Why they have to do it ?
Thanks
Ginola|||thanks all for helping.
On Mon, 12 Jan 2004 10:52:06 -0000, "Narayana Vyas Kondreddi"
<answer_me@.hotmail.com> wrote:
>N indicates that the string after it is a Unicode string. Use N prefix, only
>when comparing a value against a Unicode column, otherwise you will see
>performance degradation, as an index may not be used.
--
Ginola

Mysterious text in query result

Hi,
I have a database with a column defined as varchar(100) called Surname.
When I use Query Analyzer to retrieve data from the column and display as
text, I get strange text appearing for one of the records. Thus, the field
contains "Wilson" but when I run the following:
SELECT '''' + Surname + '''', Surnname FROM tblManagers
WHERE FirstName = 'Glenn'
I get the following result:
'Wilson d g e d w i t h t h e a ' Wilson
Where has the "d ged with the a" come from. If I show the results in a grid
the final apostrophe is missing from the first part of the query:
'Wilson
If I run a query using ADO and show the result on a web page, the extra text
is not shown.
Any ideas what is going on here?
Glenn
[Reposted, as posts from outside msnews.microsoft.com does not seem to make
it in.]
BigMan2001 (BigMan2001@.discussions.microsoft.com) writes:
> I have a database with a column defined as varchar(100) called Surname.
> When I use Query Analyzer to retrieve data from the column and display
> as text, I get strange text appearing for one of the records. Thus, the
> field contains "Wilson" but when I run the following:
> SELECT '''' + Surname + '''', Surnname FROM tblManagers
> WHERE FirstName = 'Glenn'
> I get the following result:
> 'Wilson d g e d w i t h t h e a ' Wilson
> Where has the "d ged with the a" come from. If I show the results in a
> grid the final apostrophe is missing from the first part of the query:
> 'Wilson
> If I run a query using ADO and show the result on a web page, the extra
> text is not shown.
Looks like some junk data slipped in, and there is a NUL character hiding
there. See what
SELECT convert(varbinary(100), Surname) FROM tblManagers
WHERE FisttName = 'Glenn'
returns.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.seBooks Online for SQL
Server 2005
athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000
athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Mysterious query problem?

Hey all,
strange problem here... query #1 displays 357 records correctly and all
is well. However, when placed within query #2 as a subquery, it updates
every single record in the lta table, what's going on here? any
thoughts?

1.) select *
from LTA INNER JOIN new_list
ON lta.voy = new_list.voy AND
lta.poe = new_list.poe

2.)
update lta
set lta.LL_RCVD = 'N'
where exists (select *
from LTA INNER JOIN new_list
ON lta.voy = new_list.voy AND
lta.poe = new_list.poe)Gah! What am I doing wrong? The query below is a modification of query
#2 above, yet updates 32 records (all of which are NOT located in table
new_list)??!
Please help!

update lta
set LL_RCVD = 'j'
from lta a, new_list b
where a.voy = b.voy AND
a.poe = b.poe|||On 10 Jan 2005 07:25:14 -0800, Roy wrote:

>Hey all,
>strange problem here... query #1 displays 357 records correctly and all
>is well. However, when placed within query #2 as a subquery, it updates
>every single record in the lta table, what's going on here? any
>thoughts?
>
>1.) select *
>from LTA INNER JOIN new_list
>ON lta.voy = new_list.voy AND
>lta.poe = new_list.poe
>
>2.)
>update lta
>set lta.LL_RCVD = 'N'
>where exists (select *
>from LTA INNER JOIN new_list
>ON lta.voy = new_list.voy AND
>lta.poe = new_list.poe)

Hi Roy,

The subquery on #2 doesn't reference the outer query. Hence, it returns
the same 357 rows for each row in LTA (from the outer query), so the
EXISTS predicate is always true.

You probably need

UPDATE lta
SET LL_RCVD = 'N'
WHERE EXISTS (SELECT *
FROM new_list
WHERE new_list.voy = lta.voy
AND new_list.poe = lta.poe)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||On 10 Jan 2005 07:42:14 -0800, Roy wrote:

>Gah! What am I doing wrong? The query below is a modification of query
>#2 above, yet updates 32 records (all of which are NOT located in table
>new_list)??!
>Please help!
>update lta
>set LL_RCVD = 'j'
>from lta a, new_list b
>where a.voy = b.voy AND
>a.poe = b.poe

Hi Roy,

This should affect the same rows as the query I suggested in my reply to
your other message (but this one sets LL_RVCD to 'j'; the other one sets
it to 'N').

An important difference occurs if one row in lta matches more than one row
in new_list (and, since the select returns more rows than are affected by
the update statement, this appears to be the case with your data). The
above query will repeatedly change the values for any lta row that matches
more than one new_list row (with the results being undefined, though in
you case, where the new value is a constant, the results will be as
expected); my version will simply update the rows exactly once.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||I love you forever, thanks Hugo!

Monday, March 12, 2012

Mysql Vs Mssql query

Hi,
I have a query that works perfectly in Mysql but fails in MSSQL.
Can anyone please throw light on this issue and guide me on how to avoid
this?
quote:

select cust_name,cust_email from customer,cust_departments
where customer.cust_id=cust_departments.cust_id and
cust_departments.dept_id='1' and cust.notify_ticket='1' group by
cust_departments.cust_id


The error thrown is Column 'cust_name' is invalid in the select list because
it is not contained in either an aggregate function or the GROUP BY clause.
What do I do?
Thanks and Regards,
Celia>
quote:

> select cust_name,cust_email from customer,cust_departments
> where customer.cust_id=cust_departments.cust_id and
> cust_departments.dept_id='1' and cust.notify_ticket='1' group by
> cust_departments.cust_id
>

I have no idea what you expect to see in MySQL. Why are using GROUP BY? Do
you multiple cust_name/cust_email combinations for a single cust_id? If so,
which one do you expect to show (I assume you only want one cust_id per
row)?
Perhaps you could provide schema (I have no idea what table cust_name /
cust_email belong to), sample data and desired results as per
http://www.aspfaq.com/5006|||Does MySQL not have DISTINCT? Is that why the group by is being used?
Also you should not use the old join style - update it to the ANSI syntax
select DISTINCT cust_name,cust_email
from customer
join cust_departments on customer.cust_id=cust_departments.cust_id and
cust_departments.dept_id='1'
where cust.notify_ticket='1'
celia wrote:
> Hi,
> I have a query that works perfectly in Mysql but fails in MSSQL.
> Can anyone please throw light on this issue and guide me on how to avoid
> this?
>
quote:

> select cust_name,cust_email from customer,cust_departments
> where customer.cust_id=cust_departments.cust_id and
> cust_departments.dept_id='1' and cust.notify_ticket='1' group by
> cust_departments.cust_id
>

> The error thrown is Column 'cust_name' is invalid in the select list becau
se
> it is not contained in either an aggregate function or the GROUP BY clause
.
> What do I do?
> Thanks and Regards,
> Celia
>

MySQL to SQL Server migration

Hi,
I would liked to know the SQL Server equivalent for the below MySQL query :
SELECT
a.col1,
a.col2,
max(a.col1)
FROM test a,
test1 b
WHERE a.col2 = b.col2
GROUP BY a.col1
Thanks,
SmithaYou can do it the same way except you can't just show a.col2. You use groupby, so it must belong to some logical output. You can do it like:

SELECT
a.col1,
max(a.col2), --or other functions...
max(a.col1)
FROM test a,
test1 b
WHERE a.col2 = b.col2
GROUP BY a.col1

OR

SELECT
a.col1,
a.col2,
max(a.col1)
FROM test a,
test1 b
WHERE a.col2 = b.col2
GROUP BY a.col1, a.col2

Hope it helps|||Adding all the select columns to the group by can't be the solution as the result will differ when compared to the MySQL query. Am I right ? Please advice.
Also I can't remove the select list item and replace it with aggregate function, as I require that too in my result set.|||imho, MSSQL is here logically correct. Which raw should sql give out if you use group by clause?

id | name
1 a
2 b
2 c
2 d
3 e
If you execute SELECT name, max(id) GROUP BY id, what should come out?
1 a
3 e
2 (?) <-- b, c or d?

So you have to be specific.|||MySQL always gives the first row '2 b'. I need the equivalent for this logic.|||Yes, and that's not definitely. MySQL gives out just the first row, and that's the first row saved in the table. The next time (say, after import-export) it may be an another row.|||SELECT
a.col1,
a.col2,
max(a.col1)
FROM test a,
test1 b
WHERE a.col2 = b.col2
GROUP BY a.col1, a.col2
Your above solution gives all the rows, is there any equivalent SQL Server query which fetches the first row from the table
|||SELECT DISTINCT ?|||SELECT distinct MAX(id), name FROM test3 GROUP BY id, name
Above query is not helping me ! It gives all the rows|||SELECT MAX(id), min(name) FROM test3 GROUP BY id

here you'll get the right grouping. If you take min(name) you'll get the first (alphabetically) grouped name row|||Can you show some sample data and the output for that query in MySQL? I'm not sure how it should behave, given that Col1 is both grouped and in an aggregate function, and Col2 is not even grouped... Very odd... If you can show the input you're using and the output you need, I can help you write a query for it. Also, please note whether you're using SQL Server 2000 or 2005. -- Adam MachanicSQL Server MVPhttp://www.datamanipulation.net-- <smith_kbase@.discussions.microsoft.com> wrote in message news:edc1b9b6-7367-4041-8e24-a17af5660785_WBRev1_@.discussions..microsoft.com...This post has been edited either by the author or a moderator in the Microsoft Forums: http://forums.microsoft.com Hi,I would liked to know the SQL Server equivalent for the below MySQL query :SELECTa.col1,a.col2,max(a.col1)FROM test a,test1 b WHERE a.col2 = b.col2GROUP BY a.col1Thanks,Smitha

MySQL to SQL Server - query migration

Hi,
I would liked to know the SQL Server equivalent for the below MySQL query :
SELECT
a.col1,
a.col2,
max(a.col1)
FROM test a,
test1 b
WHERE a.col2 = b.col2
GROUP BY a.col1
Thanks,
MiraJSELECT
a.col1,
a.col2,
max(a.col1)
FROM test a,
test1 b
WHERE a.col2 = b.col2
GROUP BY a.col1,a.col2