|
Hi Steve
The & characters are worrying me a bit. Which database product are you using? Under SQL-Server, you should be using "+" signs. Under Oracle you would normally use the pipe symbol.
Try replacing the entire list of columns in your select with "*". That will tell you whether the error comes from the column-list or from the from-clause. Once you know this, you should be able to narrow the problem down further.
Regards
Andy
|
|
|
|
|
Thanks Andy for the information. I'll give that a try.
Steve Welborn
Software Engineer
Inrange Consulting
|
|
|
|
|
I'll be darn..Andy it was the & that was giving it the problem. I changed it to + and it worked fine.
Thanks for the help guys. I appreciate it.
Steve Welborn
Software Engineer
Inrange Consulting
|
|
|
|
|
ISNULL(tlkpBWLSStaff.FirstName, NULL) &
ISNULL(tlkpBWLSStaff.MiddleInitialName, NULL) &
ISNULL(tlkpBWLSStaff.LastName, NULL) AS PreferredSurgeon
Not sure what you are trying to accomplish with this line. & is a bitwise operator, ISNULL([whatever],NULL) doesn't do anything productive that I can think of. Can you do a bitwise & with character data?
Are you trying to build a full name?
ISNULL(tlkpBWLSStaff.FirstName + ' ', '') +
ISNULL(tlkpBWLSStaff.MiddleInitialName + ' ', '') +
ISNULL(tlkpBWLSStaff.LastName, '') AS PreferredSurgeon
To debug the rest of you statement eliminate all tables/columns except tblPatients . Run the query and check results. Add in the next table and run again. In this way you will isolate the error in its most simplistic form.
Be aware that you are listing some columns more than once (a waste of network resources). tblPatients.* gets you all the columns in tblPatients. You then go and relist some columns individually (tblPatients.PatientHospitalNumber, etc.).
|
|
|
|
|
Great points. I can definitly see the wasted resources in this statement and will take your suggestion to shorten it.
I believe with the Name issue you mentioned, it was just putting the first, middle and last name together. Bare in mind that this came from an Access 97 (then converted to 2k) database report. I converted it to SQL Reporting and trying to redo all the bad sql statements, including this one.
Steve Welborn
Software Engineer
Inrange Consulting
|
|
|
|
|
Hi,
i have a parent and child tables. when i am deleting a row from a parent table i want to check wheter that value in Primarykey column exits in childtables or not(it is a forien key in child tables) without mentioning the child table names.ie; i should be generic..i am using sqlserver 2005.
Anu
|
|
|
|
|
Then you will have to write some SQL that examines the dependencies of a table, find the relationships then traverses it and examine the child table. You might be able to wrap this up into a UDF (User Defined Function) but I can't imagine that it would be very quick.
|
|
|
|
|
If you want it to prevent deletes if there are child rows, why not just make sure that cascading deletes is switched off on your tables?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
How can i switched of cascading deletes. actually i am not deleting the full record from parent table.just i want to check checking whether it contains child rows or not
Anu
|
|
|
|
|
OK - the cascading ability is maintained per FK relationship. As you aren't actually performing a delete - you are only doing an update, you are going to have to do this the way that Colin suggested.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
hello ,
i having a problem in SQL.
i will explain my problem with a simple example.
lets say i have a table called "MyTable" with the following headers:
SKU , TITLE , USER , PRICE , QUANTITY , TOTAL_PRICE
the values are:
avs123 ,some title , udikantz , 2.0 , 1 , 2.0
avs123 ,some title , codeproject , 2.0 , 10 , 20.0
avs123 ,some title , baboon , 2.0 , 5 , 10.0
lol22 , some title2 , hehe , 5.0 , 2 , 10.0
lol22 , some title2 , hoho , 5.0 , 1 , 5.0
i am trying to write a query that will output the following table:
SKU TITLE PRICE QUANTITY TOTAL_PRICE
------------------------------------------------------
avs123 some title 2.0 16 32
lol22 some title2 5.0 3 15
so what im trying to do exactly is to group all the SKU items with the same SKU string to one row and Sum the quantity of all the grouped SKUS
I was trying to manage that by using the distinct statement...
Net
|
|
|
|
|
You could try a GROUP BY and some aggregate functions.
SELECT SKU, TITLE, AVG(PRICE), SUM(QUANTITY), SUM(TOTAL_PRICE)<br />
FROM MyTable<br />
ORDER BY SKU, TITLE
|
|
|
|
|
if i understand what u are saying you probably ment:
SELECT SKU, TITLE, AVG(PRICE), SUM(QUANTITY), SUM(TOTAL_PRICE)
FROM MyTable
Group BY SKU, TITLE
and not
...
...
...
ORDER BY SKU, TITLE
well that is not working for me , Cause my table contain a few more fields i didnt mention in the example ,
more headers like : COLOR , SIZE , COMMENTS ,...
which may be diferent in any ROW
so when im doing
...
...
...
...
Group BY COLOR,SIZE,TITLE,SKU....ect
im getting the same table as "MyTable"
any other idea?
Net
|
|
|
|
|
udikantz wrote: Group BY SKU, TITLE
and not
ORDER BY SKU, TITLE
Oops! My bad.
udikantz wrote: well that is not working for me , Cause my table contain a few more fields i didnt mention in the example
Perhaps you should have done.
|
|
|
|
|
hey ,
is it possible to set the cells of a DataGridView so if the content
of a cell is longer than a certain amount of chars ,
the cell will split the text into few lines as needed...
as for now i get cells with long lines and i didnt find any way
to adjust the cells as multiline cells , im sure there is a way of doing that.
what properties , methods would solve my problem?
thanks.
Net
|
|
|
|
|
Have you set the cells to wrap = true
|
|
|
|
|
Hi all,
When i use order by clause in my query, it retrieves data like.....
NULL
NULL
NULL
4/10/2007
4/28/2007
5/17/2007
7/20/2007
9/10/2007
But i need it in another order, like..........
4/10/2007
4/28/2007
5/17/2007
7/20/2007
9/10/2007
NULL
NULL
NULL
Can anyone help me with this...............
thanks in advance.!
Sebastian
|
|
|
|
|
use order by desc
I Love SQL
|
|
|
|
|
Hi
thanks for your reply....but that will not work, If i use that i will get result like.....
9/10/2007
7/20/2007
5/17/2007
4/28/2007
4/10/2007
NULL
NULL
NULL
But i need result in the following order.......
4/10/2007
4/28/2007
5/17/2007
7/20/2007
9/10/2007
NULL
NULL
NULL
I hope you understood..... awaiting for your comments
Thanks once again
Sebastian
|
|
|
|
|
You could try using COALESCE (sp?) in your ORDER BY clause to replace the nulls with a far off date
ORDER BY COALESCE(MyDateColumn, '9999-12-31')
You might want to check what the maximum date permitted is in SQL Server as I don't know off the top of my head. It changes between the DATETIME and SMALLDATETIME types also.
|
|
|
|
|
Hi,
Thank you, thank you very much....that really works fine now. As you said the maximum value for datetimefield is December 31, 9999 and smalldatetime is June 6, 2079.
Best Regards
Sebastian
|
|
|
|
|
|
is this what you are looking for ....
select case when c1 = '31-dec-9999' then null else c1 end as c1 <br />
from (<br />
select top 1000 * <br />
from (<br />
select case when c1 is null then '31-dec-9999' else c1 end as c1 from a <br />
)a order by c1<br />
)a
i've checked this query with following sample table and data
CREATE TABLE a (c1 datetime)
insert into a values('01-jan-07')
insert into a values(null)
insert into a values('21-jan-07')
insert into a values('10-jan-07')
insert into a values('11-apr-07')
insert into a values(null)
insert into a values('10-apr-07')
insert into a values(null)
insert into a values('30-apr-07')
and output is
2007-01-01 00:00:00.000
2007-01-10 00:00:00.000
2007-01-21 00:00:00.000
2007-04-10 00:00:00.000
2007-04-11 00:00:00.000
2007-04-30 00:00:00.000
NULL
NULL
NULL
Regards
KP
|
|
|
|
|
Hi, thanks Kp, i have solved the issue.....
sebastian
|
|
|
|
|
you welcome.
colin's solution was simple
Regards
KP
|
|
|
|
|