Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Thursday, March 29, 2012

Drawing Circles and line and text note in report

I am not sure if this is possible with the reporting tool, but I thought I
would ask. In MS Word, you are able to select an option to â'drawâ' a line or
object on the screen. thought that it would be useful to allow a user to add
a circle or line and a text note to the report prior to printing it. I want
to know whether this is possibleExample: if I wanted to circle the name of
one employee on the report before printing it.
Is this possible with the SQL report writer?
Thanks!Currently there is no feature in RS for users to be able to modify the report in anyway after the report is generated, but would like to have this feature in the later versions.
>--Original Message--
>I am not sure if this is possible with the reporting tool, but I thought I >would ask. In MS Word, you are able to select an option to =E2?odraw=E2?=9D a line or >object on the screen. thought that it would be useful to allow a user to add >a circle or line and a text note to the report prior to printing it. I want >to know whether this is possibleExample: if I wanted to circle the name of >one employee on the report before printing it.
>Is this possible with the SQL report writer?
> >Thanks!
> >
>.
>

Tuesday, March 27, 2012

Dowt in create View

I want to create a view from dynamic tables

Query:

CREATE VIEW dbo.TrialView
AS
SELECT *
FROM (select name from dbo.sysobjects where name like 'scTabForm%' and type='u') p

Output:
Name
scTabForm0
scTabForm1

But I want all the fields from table starts with 'scTabForm'

like: select * from scTabForm0,scTabForm1,...

Regards
RaabuI think I know what you are getting at, but could you please clarify for me just a little bit? You have an unknown number of tables, with unknown structure. You want to create a view that will combine these and rename the columns to append the table they came from?

Monday, March 19, 2012

Doubts on Indexing.

Hi,

set @.DN=''

set @.DN=@.DN+'AA9999'

select @.ID = ID from TableA where status='A' and ColumnA like '%'+@.DN

ColumnA is NonClusteredIndex

When I use = symbol it goes for Index Seek (like below query) otherwise its going for table scan. Could anyone advice me which index need to be used for getting 'Index Seek' when I use like Operator. Basically TableA has millions of records.

select @.ID = ID from TableA where status='A' and Code = 'AA9999'

Regards

JMR

I think it is the normal behavior because SQL have to compare all ColumnA values with a pattern and have to go row to row; in the other select SQL look at an unique values.

So, it is recommended to avoid like operator in WHERE clause.

|||

If you use LIKE + '%xxxxx' , there is no option; It forced to use Scan. Bcs we don't know where start. When the pattern will match.

If you use LIKE + 'xxxx%', it might use Index Scan / Seek depend with your data density.

bcs the LIke 'xxxx%' will be converted as col >= 'xxxx' and col < 'xxxxY';

Doubt in select query

my table ha follow structure..
SalaryTable:
Value Salary
--
Jan 1000
Feb 2000
Mar 3000
Apr 4000
i want the o/p as..
Jan Feb Mar Apr
1000 2000 3000 4000
Pls give me a query for this
Regards,
SatheeshHi,
It is not straight forward in SQL 2000, you need to write logic. See the
below URL:-
http://www.sqlteam.com/item.asp?ItemID=2955
Thanks
hari
SQL Server MVP
"BabuLives" <satheeshbabu.b@.gmail.com> wrote in message
news:1130138243.780789.195160@.g43g2000cwa.googlegroups.com...
> my table ha follow structure..
>
> SalaryTable:
>
> Value Salary
> --
> Jan 1000
> Feb 2000
> Mar 3000
> Apr 4000
>
> i want the o/p as..
>
> Jan Feb Mar Apr
> 1000 2000 3000 4000
>
> Pls give me a query for this
>
> Regards,
> Satheesh
>

Doubt in Index

Hi EverB,

I have created a table say T1 with 5 columns (col1.....col5).
I have created an index on col4 and col5.

iam executing a select query say.

select col1,col2,col3 from t1 where col1 =0;

In the above query i hav not used the columns for which i hav created the index.My ques is-

Does the index really works when u execute the above query?

Any answer please.......
It wuld be better if u culd suggest some sites for this.

Thanks and Regds,
Arunno, for that query, the index is ignored

a good tutorial is Optimizing your MySQL Application (http://www.sitepoint.com/print/optimizing-mysql-application) even if you're using something other than mysql

Sunday, March 11, 2012

Double Left Join?

Helllo...

I need to do a query that left joins a table conditionally.

select t.*, v.vwap, a.moniker,v.dateTime
from accounts a, stocks s, trades t left join vwaps v on t.[date] = v.dateTime
where a.accountNumber = t.accountNumber AND t.symbol = s.symbol
AND a.moniker not like '%kb001%'
AND t.timeVWAP is not NULL
ORDER BY a.moniker, t.date, t.[transaction], t.symbol

but only left join vwaps if s.stockid = v.stockid

I used to have it like this.

select t.*, v.vwap, a.moniker,v.dateTime
from accounts a, trades t, stocks s left join vwaps v on s.stockID = v.stockID
where a.accountNumber = t.accountNumber AND t.symbol = s.symbol
AND a.moniker not like '%kb001%'
AND t.timeVWAP is not NULL
ORDER BY a.moniker, t.date, t.[transaction], t.symbol

in which case I would need to only join if v.dateTime = t.[date]
else just attach a NULL value.
Any idea how do to this?try this

select t.*, v.vwap, a.moniker,v.dateTime
from
accounts a,
(
stocks s
join
trades t
on t.symbol = s.symbol
)
left join
vwaps v on t.date = v.dateTime and s.stockid = v.stockid
where a.accountNumber = t.accountNumber
AND a.moniker not like '%kb001%'
AND t.timeVWAP is not NULL
ORDER BY a.moniker, t.date, t.transaction, t.symbol|||Will give it a try. Thanks.

double inner join

select a.xxxx, b.xxxxxx, d.xxxxxx
a inner join b where y=z
c inner join d where y=q.
what do these two inner joins do in simple words?
will this be the sum of the two inner joins? As if these were both separate
inner joins and the rows that match are basically appended to the rows that
match of the other. thank you. -hazzEach Join is "Joining" One 'resultset' to another 'resultset'.
a 'resultset' is either a table, or the results of joining ywo other tables
or resultsets.
So if you want to 'join' 4 tables say A, B, C, and D,
you can do it in a variety of ways. I'll put parentheses to show the order
of operations, (omitting Join conditions for clarity (On clauses)
From ( (A Join B ) Join C ) Join D -- This is default order,
without parentheses,
From A Join B Join C Join D
it would do the same,
1) Join A to B
2) Join C with the result of step 1
3) Join D with the resultset from step 2
or, you could...
From (A Join B)
Join
(C Join D)
which would be closest to what you were trying to do,
1) Join A to B
2) Join C to D
3 Join result from Step 1 to result from Step 2
"Hazz" wrote:

> select a.xxxx, b.xxxxxx, d.xxxxxx
> a inner join b where y=z
> c inner join d where y=q.
> what do these two inner joins do in simple words?
> will this be the sum of the two inner joins? As if these were both separat
e
> inner joins and the rows that match are basically appended to the rows tha
t
> match of the other. thank you. -hazz
>
>|||Also, Join conditions must use the 'On' Keyword, not 'Where' for
conditions, so to summarize, your sql should be
Select *
From (A Join B On B.y = A.z)
Join
(C Join D On D.y = C.q)
On C.q = A.q
"Hazz" wrote:

> select a.xxxx, b.xxxxxx, d.xxxxxx
> a inner join b where y=z
> c inner join d where y=q.
> what do these two inner joins do in simple words?
> will this be the sum of the two inner joins? As if these were both separat
e
> inner joins and the rows that match are basically appended to the rows tha
t
> match of the other. thank you. -hazz
>
>|||Thank you very much for your ideas. . thx -greg
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:020CB179-05D2-4D56-9815-2CF867A29A04@.microsoft.com...
> Also, Join conditions must use the 'On' Keyword, not 'Where' for
> conditions, so to summarize, your sql should be
> Select *
> From (A Join B On B.y = A.z)
> Join
> (C Join D On D.y = C.q)
> On C.q = A.q
> "Hazz" wrote:
>

Wednesday, March 7, 2012

Dont understand error...

This is failing:

// Trying to update DynamicPageContent.Html where DynamicPageContent.PageID='121'
//With
// Select Html from DynamicPageHistory where HistoryID='831'
//

Update DynamicPageContent
SET Html=(SELECT Html FROM DynamicPageHistory WHERE HistoryID='831')
WHERE PageID='121'

With the following error:

Server: Msg 279, Level 16, State 3, Line 1
The text, ntext, and image data types are invalid in this subquery or aggregate expression.

DynamicPageContent.Html is Ntext size 16 and DynamicPageHistory.Html is Ntext size 16. PageID is and int and HistoryID is an int. It fails with single quotes around 831 and 121 and it fails without single quotes. The error message is the same both ways.

Ideas?

Thanks,

Rex

Look at the error message, it indicates the HTML column (whose data type is NTEXT) can not be used in subquery. To manipulate BLOB data, you should use some system functions. You can start from here:

http://msdn.microsoft.com/library/en-us/acdata/ac_8_con_11_7zox.asp?frame=true

|||I'm not a DBA at all and the SQL syntax is weird for me in terms of ordering the operations how would I modify the above SQL to use a declared variable and insert that value? Sorry to be so simple minded on this I'm learning as I go...|||

Nevermind:) Well, you can use something like this:

DECLARE @.val_His varbinary(16)
SELECT @.val_His = textptr(Html) FROM DynamicPageContent
WHERE HistoryID='831'

DECLARE @.val_Content varbinary(16)
SELECT @.val_Content = textptr(Html) FROM DynamicPageContent
WHERE PageID='121'

WRITETEXT DynamicPageContent.Html @.val_His @.val_Content

|||After posting to you I just plain wrote the SQL Select in ASP stuffed it into a string passed it as a param to the Update and let ASP do all the thinking.

Snap-Snap-Done. :)

Thank you for the help though.

dont show select results

hi
is it possible in a query dont show the result rows'
i wanna write
select *
from table
set @.num=@.@.rowcount
and i dont wanna see all the rows affected
thanks
CarloHow about
SELECT @.num = COUNT(*) FROM table
"Carlo" <carletto.m@.NOSPAMgmail.com> wrote in message
news:%23kaDMPwrFHA.1788@.tk2msftngp13.phx.gbl...
> hi
> is it possible in a query dont show the result rows'
> i wanna write
> select *
> from table
> set @.num=@.@.rowcount
> and i dont wanna see all the rows affected
> thanks
> Carlo
>|||SET @.num =
(SELECT COUNT(*)
FROM table)
Note that @.@.ROWCOUNT will now be 1regardless of the value returned in
@.num.
David Portas
SQL Server MVP
--|||Carlo,
What for is @.num?. You can do the following:
select @.num = count(*) from t1 where ...
...
or
if exists(select * from t1 where ...)
..
AMB
"Carlo" wrote:

> hi
> is it possible in a query dont show the result rows'
> i wanna write
> select *
> from table
> set @.num=@.@.rowcount
> and i dont wanna see all the rows affected
> thanks
> Carlo
>
>|||Carlo wrote:
> hi
> is it possible in a query dont show the result rows'
> i wanna write
> select *
> from table
> set @.num=@.@.rowcount
> and i dont wanna see all the rows affected
> thanks
> Carlo
Row Affected shows up when you have not set SET NOCOUNT ON. You've
already received the answer if what you wanted was to not see the rows
themselves, but when reading your post, it's not clear what you want.
If you want to see all the rows, then define the select statement with
only the columns you need. Assuming you're fetching them on the client,
you can count the rows there.
If all you need is the rowcount for the select statement, then read the
other posts about assigning the count to a local variable.
You should always have SET NOCOUNT ON as the first statement of each
stored procedure and as the first SQL call from an application that uses
embedded SQL. That will suppress the "x Row(s) Affected" message.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||thanks
another stupid question:
can i dont write the message like :
(7 row(s) affected)
'?
thanks
carlo
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> ha scritto nel
messaggio news:ugcV$SwrFHA.1204@.TK2MSFTNGP15.phx.gbl...
> How about
> SELECT @.num = COUNT(*) FROM table
>
> "Carlo" <carletto.m@.NOSPAMgmail.com> wrote in message
> news:%23kaDMPwrFHA.1788@.tk2msftngp13.phx.gbl...
>|||SET NOCOUNT ON

don't select * but...

Read it at this link http://blogs.conchango.com/jamiethomson/archive/2006/02/21/2930.aspxthat selection from dropdown is equal to Select * . I agree but how do you not select AS400 library from dropdown? Also i have not see any other place to supply a query other than Execute Sql task .

kushpaw

kushpaw wrote:

Read it at this link http://blogs.conchango.com/jamiethomson/archive/2006/02/21/2930.aspxthat selection from dropdown is equal to Select * .

Actually, the point of that blog post was that they are NOT the same.

kushpaw wrote:

I agree but how do you not select AS400 library from dropdown? Also i have not see any other place to supply a query other than Execute Sql task .

kushpaw

In the OLE DB Source you have to choose whether to simply pick a table or supply a query.

-Jamie

|||

Jamie, i was looking for some way if query could be done in a db2 connection and avoid dropdown. Even for sql connection where would you write the query, in a script because i didnot see any such option in propery page or edit option dialog. If you could suggest any link?

many thnx,

kushpaw

|||

kushpaw wrote:

Jamie, i was looking for some way if query could be done in a db2 connection and avoid dropdown. Even for sql connection where would you write the query, in a script because i didnot see any such option in propery page or edit option dialog. If you could suggest any link?

many thnx,

kushpaw

Have you even bothered to look?

Select "SQL Command" from the 'Data Access Mode' dropdown in the OLE DB Source.

-Jamie

dont know how to make the CR sql use nested selects..

here's a SQL:

SELECT acc.client_number, lin.client_branch, reg.*
FROM CAS_CLIENT_ACCOUNT acc,
CIS_CLIENT_DETAILS det,
(SELECT cht_client_branch.index_field, cht_client_branch.client_branch,
cht_client_branch.region, cht_branch_region.branch_region
FROM cht_branch_region, cht_client_branch
WHERE cht_branch_region.index_field = cht_client_branch.region
AND cht_branch_region.institution_number = cht_client_branch.institution_number
AND cht_branch_region.institution_number = '00000005') reg,
(SELECT MAX(RECORD_DATE), client_number, institution_number, client_branch
FROM CIS_CLIENT_LINKS
WHERE institution_number = '00000005'
GROUP BY client_number, institution_number, client_branch) lin

WHERE
--links section
acc.client_number = det.client_number
AND acc.institution_number = det.institution_number
AND acc.client_number = lin.client_number
AND acc.institution_number = lin.institution_number
AND lin.client_branch = reg.index_field

--restriction section
AND acc.institution_number = '00000005'
AND acc.acct_status = '001'
AND acc.record_type = '002'
AND det.record_type = '002'

as you can see, it uses two nested selects. I'd like to know how i would get this into crystal; in the old versions you could write into the "view sql query" window. in CR10+ this isnt possible

if it's covered in the help manual for CR, please point me there to save yourself some typing :)I've been using database views for this purpose. I've also seen a screen were you could type your own SQL, this could however had been a Beta version (I was not able to find the window today). The great advantage to SQL-editor in version 8.5 is that you could use Crystal Parameters in your syntax and actually limit the value set returned to your computer.

- Jukka|||yeah.. i dont know why they make the sql view as read only in cr10+, but im looking at making a view or stored procedure on the DB server for this report... tsk|||Hi,

I tried the following i made a report selecting a single field from a table called station. Then I included a second table (machinegroup) to the report without any joins to the first table. Finally i created an SQL Expression Field that used the machinegroup table, see code below:

(select "MACHINEGROUP"."MACHINE_GROUP_NAME" from "MACHINEGROUP" "MACHINEGROUP" where "MACHINEGROUP"."MACHINE_GROUP" = "STATION"."MACHINE_GROUP")

Then i got the following SQL generated by crystal

SELECT "STATION"."STATION_CODE"
FROM "STATION" "STATION"

SELECT ((select "MACHINEGROUP"."MACHINE_GROUP_NAME" from "MACHINEGROUP" "MACHINEGROUP" where "MACHINEGROUP"."MACHINE_GROUP" = "STATION"."MACHINE_GROUP"))
FROM "MACHINEGROUP" "MACHINEGROUP", "STATION" "STATION"

This could be a workaround for your problem

- jukka|||I finally managed to find the functionality enabling free SQL-queries. Select from the Database Expert 'Add Command' from the navigation tree to our database. This opens a window where you can type your SQL command and define Crystal parameters. This is supirior to the SQL Editor found in version 10 since parameter values are actually passed to the SQL command.

- Jukka

dont insert if record exists

/*if key values exist don't insert new record*/
SELECT

/*if exists don't insert*/
CASE
WHEN ISNULL(gradeId, -1) = -1 THEN
INSERT INTO tblScores
(gtStudentId, assignmentId, score)
VALUES (@.nStudent, @.nAssignment, 0)
END

FROM tblScores
WHERE gtStudentId = @.nStudent AND assignmentId = @.nAssignment

tblScores has two fields comprising its primary key (gtStudentId, assignmentId) and the gradeId field is a required filed in this table.

I'm getting syntax errors when I click check syntax (near keywords insert from and end).

one other note: this CASE END is nested inside a BEGIN END loop, is this the problem? Is the 'End" of the 'Case' closing the 'End' of the 'Begin'?

thanksI think the problem is that the INSERT-statement is not a result_expression (see BOL). Besides, execute an INSERT-statement from a select-case? What are you trying to accomplish?|||Besides, execute an INSERT-statement from a select-case? What are you trying to accomplish?

Its rather complicated but I'll try:

This code is inside a trigger for an enrollment table. If a student joins a class late (after assignements have been assigned) then the trigger creates new records in the scores table giving the new student a 0 for each assignment already assigned to the class. If a student gets unenrolled from the class the scores are maintained in case the student gets reenrolled. If the student gets reenrolled then I want to do a select on the scores table and bypass any scores the student may have had prior to being unenrolled.
INSERT-statement is not a result_expression
How does one do a conditional INSERT?|||IF NOT EXISTS(
SELECT TOP 1 gradeId
FROM tblScores
WHERE
gtStudentId = @.nStudent
AND assignmentId = @.nAssignment)
BEGIN

INSERT INTO tblScores (
gtStudentId,
assignmentId,
score)

SELECT
@.nStudent,
@.nAssignment,
0
END|||I forget which site...but we just did this...Gotta find the code I wrote...

Why would you want to double every access to the database?

Just handle the dup key error...in a calling sproc or the application...

EDIT: It was originally about Contraints...same thing

USE Northwind
GO

CREATE TABLE myTable99(Col1 char(1), CHECK(Col1 IN ('Y','N')))
GO

CREATE PROC mySproc99 @.x char(1) AS INSERT INTO myTable99 SELECT @.x RETURN
GO

CREATE PROC mySproc00
AS
DECLARE @.rc int
EXEC @.rc = mySproc99 'Y'
SELECT @.rc, @.@.ERROR
EXEC @.rc = mySproc99 'B'
SELECT @.rc, @.@.ERROR
GO

EXEC mySproc00
GO

DROP PROC mySproc00
DROP PROC mySproc99
DROP TABLE myTable99
GO|||I did not understand very clearly what you are trying to do... is it inserting into your table only those records that _do not already exist_ in that table?

If so, ty this:

Insert into tblScores (gtStudentId, assignmentId, score)

VALUES (@.nStudent, @.nAssignment, 0)

Where (not exists (Select * from tblScores
Where WHERE gtStudentId = @.nStudent
AND assignmentId = @.nAssignment))|||My Point, just attempt the insert...and trap the Error if it fails

Don't make 2 data access attempts to the database

Friday, February 24, 2012

Domain not show select user location dialog

I have a laptop with SQL Server 2005 Express installed and when I want
to add a user to a database the only location I can select from is the
local machine. The machine is part of a SBS domain and I want a
domain user to rights through NT authentication. How do I get the
domain so show up in the list of locations?The SQL Server Services need to be started with a domain account that has
rights to be able to browse the directory. My guess is that you've got the
services started up as system or local accounts.
"Van" wrote:

> I have a laptop with SQL Server 2005 Express installed and when I want
> to add a user to a database the only location I can select from is the
> local machine. The machine is part of a SBS domain and I want a
> domain user to rights through NT authentication. How do I get the
> domain so show up in the list of locations?
>

Friday, February 17, 2012

Doing a SELECT x FROM y WHERE z IN (@param) in stored procedure?

Hello,

I have a table with a foreign key field. I need to retrieve all the records where the foreign key matches any of a set. In plain ol' SQL this is accomplished with the IN(a,b,c) statement but I can't get that to work in a stored procedure.

How would I do this? I can imagine that I could parse the input string and create a temporary table and use that to do a join but that seems rather convoluted.

Any tips highly appreciated! If I'm not being clear I'll gladly post more details.

Thanks,

Noc

PS SQL 2000, ASP.NET 1.1, VS 2003.Have a look at the following article:

http://www.sqlteam.com/item.asp?ItemID=11499|||Many thanks! Looks like I was on the righ track with the temporary table idea but it sure is a lot easier to implement with that sample code.

Doing a SELECT on a different field than the field in the GROUP BY

I'm using SQL Server 2005.

I've got table tblSaleAddresses which looks something like this:

AddressID SaleID Address1 Address2 ..... DateEffective
- -
1 100 Unit 20 100 Easy St 1 Feb 04
2 100 10 Any St 1 Oct 05
3 101 85 Main St 1 Mar 04
4 101 20 Lovers Ln 15 Sep 05

I want to select the current address for each SaleID - that is the address for each SaleID WHERE Max(DateEffective) and WHERE DateEffective <= GETDATE().

In the case above, I should get AddressID 1 (AddressID 2 isn't yet effective because it's still in the future) for SaleID 100 and AddressID 4 for SaleID 101.

I'm having trouble because I want to SELECT AddressID but GROUP BY SaleID.

I know you can do a GROUP BY subquery and then join on the SaleID and DateEffective, but it doesn't seem right to me you have to join on a date field (which theorectically isn't very unique). I expected that there would by a statement that would allow you to select the specific AddressID for the MAX(DateEffective)?

Or have I organised my data in the wrong way? And if so, what should I have done differently?

Here's the SELECT statement that joins on the date field:

SELECT t.*

FROM tblSaleAddresses t

INNER JOIN(

SELECT SaleID, MAX(DateEffective) AS MaxDateEffective

FROM tblSaleAddresses

WHERE DateEffective <= GETDATE()

GROUP BY SaleID

) d On t.SaleID = d.SaleID And t.DateEffective = d.MaxDateEffective

Thanks!

I posted few queries that show how to do this for a similar problem. Please see the thread titled "Get latest purchase of each vender". Here are few queries:

-- Works from SQL70 onwards:
select t1.*
from tblSaleAddresses as t1
where t1.AddressId = (select top 1 t2.AddressId
from tblSaleAddresses as t2
where t2.SaleID = t1.SaleID
and t2.DateEffective <= CURRENT_TIMESTAMP
order by t2.DateEffective DESC)
and t1.DateEffective <= CURRENT_TIMESTAMP;

-- SQL2005 specific:

select t2.*

from (

select t1.*
, ROW_NUMBER() OVER(PARTITION BY t1.SaleID ORDER BY t1.DateEffective DESC, t1.AddressID DESC) as AddrSeq
from tblSaleAddresses as t1
where t1.DateEffective <= CURRENT_TIMESTAMP
) as t2
where t2.AddrSeq = 1;

-- ANSI SQL query
select t1.*
from tblSaleAddresses as t1
join (
-- I concatenate date & id as binary data and take MAX on that first
-- then you can parse the address id of the max value
-- this works for positive values of AddressId and Date
-- you can character values that sorts correctly also.
select cast(right(max(cast(convert(char(8), t2.DateEffective, 112) as binary(8))
+ cast(t2.AddressID as binary(4))), 4) as int)
from tblSaleAddresses as t2
where t2.DateEffective <= CURRENT_TIMESTAMP
group by t2.SaleID
) as t3(AddressId)
on t3.AddressId = t1.AddressId;

|||Thanks! I chose the SQL 2005 option and it worked perfectly.

I was already starting down the path of the new ranking functions including ROW_NUMBER, but I was still trying to figure it out.

Thanks for your help!

Regards,

Doing a partial replace of a field

Andy
You should be able to do this using the REPLACE function.
ie.
SELECT REPLACE('have a nice day', ' ', ' ')
Returns:
have a nice day
- Peter Ward
WARDY IT Solutions
"Andy" wrote:

> How could I do a replace of " " to " " in a string were the string is a
> field and the values are variable. I would like to use Enterprise Manager
or
> a stored proc.
> IE. Node.Nodename is equal to "have a nice day" I want to replace the "
> " with " " after nice.Not just a sentence. How do you do it for a field in a database table. I
would like to do it in Enterprise Manager Query or Query Builder. There are
also allot of sentences with varying text.
"P. Ward" wrote:
> Andy
> You should be able to do this using the REPLACE function.
> ie.
> SELECT REPLACE('have a nice day', ' ', ' ')
> Returns:
> have a nice day
>
> - Peter Ward
> WARDY IT Solutions
>
> "Andy" wrote:
>|||update table
set field = replace( field , 'twospaces' , 'onespace' );
where
field like '%twospaces%'
"Andy" <Andy@.discussions.microsoft.com> wrote in message
news:4183FA77-4739-4526-94EB-C2664A4CC2B6@.microsoft.com...
> Not just a sentence. How do you do it for a field in a database table. I
> would like to do it in Enterprise Manager Query or Query Builder. There
are
> also allot of sentences with varying text.
> "P. Ward" wrote:
>
a
Manager or
the "|||Although, saying that LIKE may ignore whitespace.
You can use where (CHARINDEX(field , 'twospaces')>0) - but this will not use
any indexing and will probably be slower.
"Rebecca York" <rebecca.york {at} 2ndbyte.com> wrote in message
news:434fb7dc$0$136$7b0f0fd3@.mistral.news.newnet.co.uk...
> update table
> set field = replace( field , 'twospaces' , 'onespace' );
> where
> field like '%twospaces%'
> "Andy" <Andy@.discussions.microsoft.com> wrote in message
> news:4183FA77-4739-4526-94EB-C2664A4CC2B6@.microsoft.com...
I
> are
is
> a
> Manager or
> the "
>|||I tried this in query analyzer:
UPDATE dbo.MA_Node
SET NodeName = replace(NodeName, ' ', ' ');
WHERE (CHARINDEX(NodeName, ' ')>0)
and got this:
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'WHERE'.
same for
"Rebecca York" wrote:

> update table
> set field = replace( field , 'twospaces' , 'onespace' );
> where
> field like '%twospaces%'
> "Andy" <Andy@.discussions.microsoft.com> wrote in message
> news:4183FA77-4739-4526-94EB-C2664A4CC2B6@.microsoft.com...
> are
> a
> Manager or
> the "
>
>|||Try removing the semi-colon at the end of the second line. That is a typo
(it signifies the end of a statement).
"Andy" <Andy@.discussions.microsoft.com> wrote in message
news:857EBD97-E2B3-4195-BEC1-7245F84BD3D2@.microsoft.com...
>I tried this in query analyzer:
> UPDATE dbo.MA_Node
> SET NodeName = replace(NodeName, ' ', ' ');
> WHERE (CHARINDEX(NodeName, ' ')>0)
> and got this:
> Server: Msg 156, Level 15, State 1, Line 3
> Incorrect syntax near the keyword 'WHERE'.
> same for
> "Rebecca York" wrote:
>|||On Fri, 14 Oct 2005 15:26:42 +0100, "Rebecca York" <rebecca.york {at}
2ndbyte.com> wrote:

>Although, saying that LIKE may ignore whitespace.
Hi Rebecca,
I don't know who told you that, but he/she has misinformed you:
CREATE TABLE Test
(a varchar(20) NOT NULL)
INSERT INTO Test (a)
SELECT 'One space'
UNION
SELECT 'Two spaces'
UNION
SELECT 'Three spaces'
go
SELECT a
FROM Test
WHERE a LIKE '% %'
go
DROP TABLE Test
go
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Tuesday, February 14, 2012

Does the order matter

Hi,
I've been always wondering if the join order in select statement matter, for
example, I expected these two statements have different execution time but
they seem to have the same execution plan.
select ...
from ( SmallTableA A join SmallTableB B on A.id = b.id ) join BigTableX X on
x.id = a.id
comparing with
select ...
from ( BigTableX X join SmallTableA A on x.id = a.id ) join SmallTableB B
on A.id = b.id
I have the same question about the order of AND and OR operand.
select ...
from MyTable
where City = @.City AND StreetAddress = @.StreetAddress
comparing with
select ...
from MyTable
where StreetAddress = @.StreetAddress AND City = @.City
Thank you very muchOn Tue, 27 Sep 2005 15:54:16 -0700, Zeng wrote:

>I've been always wondering if the join order in select statement matter
(snip)
>I have the same question about the order of AND and OR operand.
(snip)
Hi Zeng,
The query optimizer is free to reorder all elements in your query, as
long as the results are unaffected. So you'll probably get the same
execution plan for your different queries.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Zeng,
I think the order does matter when performing OUTER JOINS and when combining
ANDs and ORs.
HTH
Jerry
"Zeng" <Zeng5000@.hotmail.com> wrote in message
news:ug8swc7wFHA.1168@.TK2MSFTNGP15.phx.gbl...
> Hi,
> I've been always wondering if the join order in select statement matter,
> for
> example, I expected these two statements have different execution time but
> they seem to have the same execution plan.
> select ...
> from ( SmallTableA A join SmallTableB B on A.id = b.id ) join BigTableX X
> on
> x.id = a.id
> comparing with
> select ...
> from ( BigTableX X join SmallTableA A on x.id = a.id ) join SmallTableB B
> on A.id = b.id
>
> I have the same question about the order of AND and OR operand.
> select ...
> from MyTable
> where City = @.City AND StreetAddress = @.StreetAddress
> comparing with
> select ...
> from MyTable
> where StreetAddress = @.StreetAddress AND City = @.City
>
> Thank you very much
>|||I'm not sure what you mean by combining ANDs and ORs, would you mind
explaining? thanks!
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:eBeo0k7wFHA.3152@.TK2MSFTNGP10.phx.gbl...
> Zeng,
> I think the order does matter when performing OUTER JOINS and when
combining
> ANDs and ORs.
> HTH
> Jerry
> "Zeng" <Zeng5000@.hotmail.com> wrote in message
> news:ug8swc7wFHA.1168@.TK2MSFTNGP15.phx.gbl...
but
X
B
>|||You missed the most basic idea of declarative languages. You tell the
compiler WHAT you want and the compiler figures out HOW to do it. Have
you had a course on progamming languages yet?
Join order does not matter. The optimizer can change it based on
current stats and indexing.|||Zeng,
R=1 AND S=1 AND T=2 OR U=3 AND V=4 etc... I use parens for something like
this.
HTH
Jerry
"Zeng" <Zeng5000@.hotmail.com> wrote in message
news:OBzlmC9wFHA.2792@.tk2msftngp13.phx.gbl...
> I'm not sure what you mean by combining ANDs and ORs, would you mind
> explaining? thanks!
>
> "Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
> news:eBeo0k7wFHA.3152@.TK2MSFTNGP10.phx.gbl...
> combining
> but
> X
> B
>|||Joe,
So the order of the join clauses doesn't matter when you're using multiple
joins and join types in the same statment i.e., LEFT, RIGHT, INNER etc...?
But the order of the tables listed for a LEFT or RIGHT join does matter
right? You know T-SQL 100x better than me so...
Thanks
Jerry
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1127874943.221690.200070@.f14g2000cwb.googlegroups.com...
> You missed the most basic idea of declarative languages. You tell the
> compiler WHAT you want and the compiler figures out HOW to do it. Have
> you had a course on progamming languages yet?
> Join order does not matter. The optimizer can change it based on
> current stats and indexing.
>|||Order doesn't matter, unless you force it with optimizer hints.
"Zeng" <Zeng5000@.hotmail.com> wrote in message
news:ug8swc7wFHA.1168@.TK2MSFTNGP15.phx.gbl...
> Hi,
> I've been always wondering if the join order in select statement matter,
> for
> example, I expected these two statements have different execution time but
> they seem to have the same execution plan.
> select ...
> from ( SmallTableA A join SmallTableB B on A.id = b.id ) join BigTableX X
> on
> x.id = a.id
> comparing with
> select ...
> from ( BigTableX X join SmallTableA A on x.id = a.id ) join SmallTableB B
> on A.id = b.id
>
> I have the same question about the order of AND and OR operand.
> select ...
> from MyTable
> where City = @.City AND StreetAddress = @.StreetAddress
> comparing with
> select ...
> from MyTable
> where StreetAddress = @.StreetAddress AND City = @.City
>
> Thank you very much
>|||As long as you join no more than 4 or 5 tables, in that case order
usually should not matter.
Only in a perfect world order does not matter at all.
In reality, if you join too many tables, it is impossible for the
optimizer to consider all the permutations, so the optimizer will
consider only some permutations, then quit.
Just think: even with just 5 tables there are 5*4*3*2=120 possible join
orders, and I wasn't considereing different indexes yet.|||You are correct--sort of, but there's no way to know which permutations will
be considered. There's no documentation that the optimizer applies any
deferrence to the order specified in the query. If order matters, then you
should specify optimizer hints like FORCE ORDER or use SET FORCEPLAN ON.
"Alexander Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
news:1127923668.694625.281030@.f14g2000cwb.googlegroups.com...
> As long as you join no more than 4 or 5 tables, in that case order
> usually should not matter.
> Only in a perfect world order does not matter at all.
> In reality, if you join too many tables, it is impossible for the
> optimizer to consider all the permutations, so the optimizer will
> consider only some permutations, then quit.
> Just think: even with just 5 tables there are 5*4*3*2=120 possible join
> orders, and I wasn't considereing different indexes yet.
>