Showing posts with label queries. Show all posts
Showing posts with label queries. Show all posts

Friday, March 30, 2012

Newbie question on SQL Query writing

Hi,

I am new to writing SQL queries in MS SQL & would like to do the
following: Write a query to retrieve all strings that start with a
particular value.

Basically, I am looking for the SQL equivalent of the regex "^".

Thanks,
AshokSELECT column1 FROM mytable WHERE charindex('Search Text', column1) = 1|||On 18 May 2005 08:01:46 -0700, ashok.anbalan@.gmail.com wrote:

>Hi,
>I am new to writing SQL queries in MS SQL & would like to do the
>following: Write a query to retrieve all strings that start with a
>particular value.
>Basically, I am looking for the SQL equivalent of the regex "^".
>Thanks,
>Ashok

Hi Ashok,

Assuming they need to start with 'a':

SELECT Column list
FROM MyTable
WHERE TheStringColumn LIKE 'a%'

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Monday, March 26, 2012

Newbie question

Hi, I am new to reporting services, and I wonder if I am limited to sql queries or can I program reports? This might sound stupid but I have never had to write reports so I am not sure what to look for.

I've been using RS for about 3 months now. You can use SQL queries to populate your datasets, but you can write code to "dynamically" generate those queries.

I'd suggest picking up one of the few RS books out there, like the "Reporting Services in Action" or "Hitchhikers Guide.." books.

|||but does it let you use dataset created at runtime as a source of report?

Saturday, February 25, 2012

newbie - empty result set for all queries?

I am a newbie and have installed SQL Server myself on my home machine,
where I'm having problems. When I run the Query Analyzer, I get an
empty result set for all queries, with the message, "The command(s)
completed successfully." So, for instance, if I were to go to
Northwind and type "SELECT * from Employees", which we KNOW isn't
empty, all I see is "The command(s) completed successfully." How do I
get query results?

I thought maybe the problem was permissions. I'm logged into my local
server, which is the computer on which I'm running. The owner is just
"ZIPPY/Owner", ZIPPY being my machine name; since I'm the only one who
uses the computer, I don't even log in, I just take the default "Owner"
account. I start up the SQL analyzer with Windows credentials.

Anyone have a clue what I'm doing wrong?shelah (shelah2@.verizon.net) writes:
> I am a newbie and have installed SQL Server myself on my home machine,
> where I'm having problems. When I run the Query Analyzer, I get an
> empty result set for all queries, with the message, "The command(s)
> completed successfully." So, for instance, if I were to go to
> Northwind and type "SELECT * from Employees", which we KNOW isn't
> empty, all I see is "The command(s) completed successfully." How do I
> get query results?

You are not even getting an empty result set. Apparently you are in some
sort of noexec mode where the query is sent to SQL Server for validation
only.

There are a couple of ways to get this behaviour. First make sure that
you press the green arrow to run the query. The blue tick is for validation
only.

If the problem is not that simple, check Tools->Options->Connection
properties. If any of SET NOEXEC ON or SET PARSEONLY ON are checked,
uncheck them.

If this does not help, send these commands to SQL Server:

SET PARSEONLY OFF
SET NOEXEC OFF
SET FMTONLY OFF

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thank you, that was an enormous help. You were right; I was clicking
the check and not the green arrow. A great relief to know that I have a
usable database and don't have to do some wierd chown gyrations.

*** Sent via Developersdex http://www.developersdex.com ***|||thanks it was a great help even to me
Erland Sommarskog wrote:
> shelah (shelah2@.verizon.net) writes:
> > I am a newbie and have installed SQL Server myself on my home machine,
> > where I'm having problems. When I run the Query Analyzer, I get an
> > empty result set for all queries, with the message, "The command(s)
> > completed successfully." So, for instance, if I were to go to
> > Northwind and type "SELECT * from Employees", which we KNOW isn't
> > empty, all I see is "The command(s) completed successfully." How do I
> > get query results?
> You are not even getting an empty result set. Apparently you are in some
> sort of noexec mode where the query is sent to SQL Server for validation
> only.
> There are a couple of ways to get this behaviour. First make sure that
> you press the green arrow to run the query. The blue tick is for validation
> only.
> If the problem is not that simple, check Tools->Options->Connection
> properties. If any of SET NOEXEC ON or SET PARSEONLY ON are checked,
> uncheck them.
> If this does not help, send these commands to SQL Server:
> SET PARSEONLY OFF
> SET NOEXEC OFF
> SET FMTONLY OFF
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp|||To avoid this in the future just hit F5

http://sqlservercode.blogspot.com/

Monday, February 20, 2012

Newb: Managing multiple queries

I am currently using enterprise manager to run multiple queries on a
single table in a DB. I refresh these queries every few minutes. Due
to the huge number of them I was looking for a better way (or should I
just say "a way") to manage/save these queries so I can recall them
easier/faster for monitoring purposes. Suggestions?

TIA.Hi,

Maybe creating a stored procedure (or more, if the queries are logically
grouped) will help you. Then you would need just to execute the stored
procedures in Query Analyzer (which is the tool intended to run queries
anyway). Alternatively you can save the queries to a script file, and then
open and run in Query Analyzer.

HTH,

Plamen Ratchev
http://www.SQLStudio.com|||On Thu, 6 Dec 2007 10:38:06 -0800 (PST), Akhenaten
<jonkokko@.gmail.comwrote:

If I understand you correctly you need an application (Access ADP, or
..NET) to call your queries based on a timer or a button click. SQL
Server tools alone are probably not going to do the trick.

-Tom.

Quote:

Originally Posted by

>I am currently using enterprise manager to run multiple queries on a
>single table in a DB. I refresh these queries every few minutes. Due
>to the huge number of them I was looking for a better way (or should I
>just say "a way") to manage/save these queries so I can recall them
>easier/faster for monitoring purposes. Suggestions?
>
>TIA.

|||On Dec 6, 10:45 pm, "Plamen Ratchev" <Pla...@.SQLStudio.comwrote:

Quote:

Originally Posted by

Hi,
>
Maybe creating a stored procedure (or more, if the queries are logically
grouped) will help you. Then you would need just to execute the stored
procedures in Query Analyzer (which is the tool intended to run queries
anyway). Alternatively you can save the queries to a script file, and then
open and run in Query Analyzer.
>
HTH,
>
Plamen Ratchevhttp://www.SQLStudio.com


Are there examples of "script files"? I have a few files that are used
for creating databases and tables, but somehow I think there is more
potential in using scripts.

Thanks|||Under "script files" I meant to save your frequently used SQL code to a
file, preferably with extension ".sql". Since you indicate you already save
your code to files, then you have your script files.

In SQL Server 2005, the SQL Server Management Studio adds a new capability
to organize scripts in projects (very similar to Visual Studio projects). It
is accessible via the File menu in SSMS (File -New - Project -SQL
Server Scripts template).

Script files are good because they can be easily added to a source control
system.

HTH,

Plamen Ratchev
http://www.SQLStudio.com