Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

Sunday, March 25, 2012

Cant sort a text field!

Hi
ive got a table and contains a surname text field. Why cant i do a select statement ORDER BY surname. I get an error saying i cant sort a text field! how do i go around it!

thanksYou do ANSI SQL ALTER Table and change text to Varchar 40 because text cannot be used for things like name that can be covered with Varchar 40 or 50 at most. Then do ORDER BY. Hope this helps.|||

Your surname filed is a text datatype field which cannot be sorted.

You need change this field to varchar(50) or nvarchar(50) data type to allow you sort on it.

Limno

Thursday, March 22, 2012

Can't select from 1 table

Any ideas why I can't select anything from 1 table? If I try to execute a
select statement (even Top 1), the statement just hangs. We constantly have
to restart SQL Server to "free" up the problem, but it keeps coming back.
Any ideas what's going on?
Thanks.
Sql 2000
Have your tried to select data from the table using NOLOCK hint?
There can be some blocking problem (some locks on your table that do not
allow other locks). Use sp_lock system stored procedure to find the locks on
your table (especially look for X - eXclusive locks, identify your table by
object_id - use OBJECT_ID function to know the ID). Then you can use sp_who
system stored procedure to find the process (its spid is returned by
sp_lock) that puts those locks and finally you can kill the proper session
(using kill statement). You cal also use Enterprise Manager and its
Management section.
The remedies for blocking:
- always close (commit or rollback) transactions,
- keep transactions short,
- use the proper transaction isolation level.
If it is blocking problem, try to isolate the query or procedure causing the
problem (use Profiler to catch batch executions, locks being required and
lock escalations).
Regards
Pawel Potasinski
Uytkownik <-> napisa w wiadomoci
news:OPD%232lT0HHA.1484@.TK2MSFTNGP06.phx.gbl...
> Any ideas why I can't select anything from 1 table? If I try to execute a
> select statement (even Top 1), the statement just hangs. We constantly
> have to restart SQL Server to "free" up the problem, but it keeps coming
> back.
> Any ideas what's going on?
> Thanks.
> Sql 2000
>
|||Thanks...we just found that there was a lock on the table by a process id,
but this has happened several times in the last few days, whereas it never
used to happen.
Still looking into it. Thanks for the info.
"Pawel Potasinski" <pawel.potasinski@.gmail.com> wrote in message
news:eUxUwtT0HHA.4816@.TK2MSFTNGP04.phx.gbl...
> Have your tried to select data from the table using NOLOCK hint?
> There can be some blocking problem (some locks on your table that do not
> allow other locks). Use sp_lock system stored procedure to find the locks
> on your table (especially look for X - eXclusive locks, identify your
> table by object_id - use OBJECT_ID function to know the ID). Then you can
> use sp_who system stored procedure to find the process (its spid is
> returned by sp_lock) that puts those locks and finally you can kill the
> proper session (using kill statement). You cal also use Enterprise Manager
> and its Management section.
> The remedies for blocking:
> - always close (commit or rollback) transactions,
> - keep transactions short,
> - use the proper transaction isolation level.
> If it is blocking problem, try to isolate the query or procedure causing
> the problem (use Profiler to catch batch executions, locks being required
> and lock escalations).
> --
> Regards
> Pawel Potasinski
>
> Uytkownik <-> napisa w wiadomoci
> news:OPD%232lT0HHA.1484@.TK2MSFTNGP06.phx.gbl...
>

Can't select from 1 table

Any ideas why I can't select anything from 1 table? If I try to execute a
select statement (even Top 1), the statement just hangs. We constantly have
to restart SQL Server to "free" up the problem, but it keeps coming back.
Any ideas what's going on?
Thanks.
Sql 2000Have your tried to select data from the table using NOLOCK hint?
There can be some blocking problem (some locks on your table that do not
allow other locks). Use sp_lock system stored procedure to find the locks on
your table (especially look for X - eXclusive locks, identify your table by
object_id - use OBJECT_ID function to know the ID). Then you can use sp_who
system stored procedure to find the process (its spid is returned by
sp_lock) that puts those locks and finally you can kill the proper session
(using kill statement). You cal also use Enterprise Manager and its
Management section.
The remedies for blocking:
- always close (commit or rollback) transactions,
- keep transactions short,
- use the proper transaction isolation level.
If it is blocking problem, try to isolate the query or procedure causing the
problem (use Profiler to catch batch executions, locks being required and
lock escalations).
--
Regards
Pawel Potasinski
U¿ytkownik <-> napisa³ w wiadomo¶ci
news:OPD%232lT0HHA.1484@.TK2MSFTNGP06.phx.gbl...
> Any ideas why I can't select anything from 1 table? If I try to execute a
> select statement (even Top 1), the statement just hangs. We constantly
> have to restart SQL Server to "free" up the problem, but it keeps coming
> back.
> Any ideas what's going on?
> Thanks.
> Sql 2000
>|||Thanks...we just found that there was a lock on the table by a process id,
but this has happened several times in the last few days, whereas it never
used to happen.
Still looking into it. Thanks for the info.
"Pawel Potasinski" <pawel.potasinski@.gmail.com> wrote in message
news:eUxUwtT0HHA.4816@.TK2MSFTNGP04.phx.gbl...
> Have your tried to select data from the table using NOLOCK hint?
> There can be some blocking problem (some locks on your table that do not
> allow other locks). Use sp_lock system stored procedure to find the locks
> on your table (especially look for X - eXclusive locks, identify your
> table by object_id - use OBJECT_ID function to know the ID). Then you can
> use sp_who system stored procedure to find the process (its spid is
> returned by sp_lock) that puts those locks and finally you can kill the
> proper session (using kill statement). You cal also use Enterprise Manager
> and its Management section.
> The remedies for blocking:
> - always close (commit or rollback) transactions,
> - keep transactions short,
> - use the proper transaction isolation level.
> If it is blocking problem, try to isolate the query or procedure causing
> the problem (use Profiler to catch batch executions, locks being required
> and lock escalations).
> --
> Regards
> Pawel Potasinski
>
> U¿ytkownik <-> napisa³ w wiadomo¶ci
> news:OPD%232lT0HHA.1484@.TK2MSFTNGP06.phx.gbl...
>> Any ideas why I can't select anything from 1 table? If I try to execute a
>> select statement (even Top 1), the statement just hangs. We constantly
>> have to restart SQL Server to "free" up the problem, but it keeps coming
>> back.
>> Any ideas what's going on?
>> Thanks.
>> Sql 2000
>

Can't select from 1 table

Any ideas why I can't select anything from 1 table? If I try to execute a
select statement (even Top 1), the statement just hangs. We constantly have
to restart SQL Server to "free" up the problem, but it keeps coming back.
Any ideas what's going on?
Thanks.
Sql 2000Have your tried to select data from the table using NOLOCK hint?
There can be some blocking problem (some locks on your table that do not
allow other locks). Use sp_lock system stored procedure to find the locks on
your table (especially look for X - eXclusive locks, identify your table by
object_id - use OBJECT_ID function to know the ID). Then you can use sp_who
system stored procedure to find the process (its spid is returned by
sp_lock) that puts those locks and finally you can kill the proper session
(using kill statement). You cal also use Enterprise Manager and its
Management section.
The remedies for blocking:
- always close (commit or rollback) transactions,
- keep transactions short,
- use the proper transaction isolation level.
If it is blocking problem, try to isolate the query or procedure causing the
problem (use Profiler to catch batch executions, locks being required and
lock escalations).
Regards
Pawel Potasinski
Uytkownik <-> napisa w wiadomoci
news:OPD%232lT0HHA.1484@.TK2MSFTNGP06.phx.gbl...
> Any ideas why I can't select anything from 1 table? If I try to execute a
> select statement (even Top 1), the statement just hangs. We constantly
> have to restart SQL Server to "free" up the problem, but it keeps coming
> back.
> Any ideas what's going on?
> Thanks.
> Sql 2000
>|||Thanks...we just found that there was a lock on the table by a process id,
but this has happened several times in the last few days, whereas it never
used to happen.
Still looking into it. Thanks for the info.
"Pawel Potasinski" <pawel.potasinski@.gmail.com> wrote in message
news:eUxUwtT0HHA.4816@.TK2MSFTNGP04.phx.gbl...
> Have your tried to select data from the table using NOLOCK hint?
> There can be some blocking problem (some locks on your table that do not
> allow other locks). Use sp_lock system stored procedure to find the locks
> on your table (especially look for X - eXclusive locks, identify your
> table by object_id - use OBJECT_ID function to know the ID). Then you can
> use sp_who system stored procedure to find the process (its spid is
> returned by sp_lock) that puts those locks and finally you can kill the
> proper session (using kill statement). You cal also use Enterprise Manager
> and its Management section.
> The remedies for blocking:
> - always close (commit or rollback) transactions,
> - keep transactions short,
> - use the proper transaction isolation level.
> If it is blocking problem, try to isolate the query or procedure causing
> the problem (use Profiler to catch batch executions, locks being required
> and lock escalations).
> --
> Regards
> Pawel Potasinski
>
> Uytkownik <-> napisa w wiadomoci
> news:OPD%232lT0HHA.1484@.TK2MSFTNGP06.phx.gbl...
>

Can't select a datetime field in a query without time portion

Hi,
I am doing some project with SQL Server 2000 and C#. I am using a
SELECT statement to get a column and to bind it to a dropdown list. The
column is a datetime format. I don't need time portion of it. Before I
tried any CONVERT functions my query looked like this:
SELECT DISTINCT DateEntered FROM TBL_PTM_Report
I can get the data this way but only with time portion in it. I read
about CONVERT but can't get it working. I am getting all kinds of error
messages from Visual Studio.
I tried the lowwoling:
SELECT COVVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report
It didn't work. I need data in the following format MM/DD/YYYY
Thank you,
Stan> SELECT COVVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report
CONVERT.
AMB
"suslishe@.mail.ru" wrote:

> Hi,
> I am doing some project with SQL Server 2000 and C#. I am using a
> SELECT statement to get a column and to bind it to a dropdown list. The
> column is a datetime format. I don't need time portion of it. Before I
> tried any CONVERT functions my query looked like this:
> SELECT DISTINCT DateEntered FROM TBL_PTM_Report
> I can get the data this way but only with time portion in it. I read
> about CONVERT but can't get it working. I am getting all kinds of error
> messages from Visual Studio.
> I tried the lowwoling:
>
> SELECT COVVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report
> It didn't work. I need data in the following format MM/DD/YYYY
> Thank you,
> Stan
>|||This was my typing mistake, sorry! The statement looks like this:
SELECT CONVERT(CHAR(10), DateEntered, 101) FROM TBL_PTM_Report|||I just ran this in query analyser and everything works! But Visual
Studio gives me an error.

Sunday, March 11, 2012

can't return zero when no rows exist using aggregate function sum

Hi,
I'm having a heck of a time trying to get SQL Server 2000 to return a
zero (0) if no rows are returned in a sum() statement. I know in
Oracle you wrap an NVL around the whole shebang, and in Googling it
seems as if SQL Server should work this way, too. But I cannot get it
to work, I just keep getting null.
I have tried:
what I thought would work:
SELECT ISNULL(SUM(ISNULL(PointValue, 0)), 0)
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '2/24/2005' AND getdate()
GROUP BY [File #]
a case statement testing for null:
SELECT CASE
WHEN SUM(ISNULL(PointValue, 0)) IS NULL THEN 0
ELSE SUM(ISNULL(PointValue, 0))
END
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '2/24/2005' AND getdate()
GROUP BY [File #]
wrapping the whole select statement in ISNULL as a subquery:
SELECT ISNULL((SELECT SUM(ISNULL(PointValue, 0))
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '2/24/2005' AND getdate()), 0)
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '2/24/2005' AND getdate()
and then to make sure what I was getting back was null and not empty
...something:
declare
@.n_sum numeric(6, 2)
SELECT @.n_sum = ISNULL(SUM(ISNULL(PointValue, 0)), 0)
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '2/24/2005' AND getdate()
GROUP BY [File #]
print 'sum is: ' + convert(char(8), isnull(@.n_sum, 0))
sum is: 0.00
What the heck am I doing wrong? I tried setting ANSI_NULL off and on,
etc...but no go. I guess I could get around by using the variable and
then returning that to the VB (since this is a stored proc used to find
one value to return to the VB6 program), but that seems kind of messy.
I would appreciate any help!
TIA
PatCould you provide actual specs and desired results?
http://www.aspfaq.com/5006

> I'm having a heck of a time trying to get SQL Server 2000 to return a
> zero (0) if no rows are returned in a sum() statement.|||I need to say this - I inherited this code and database structure!!!!
CREATE TABLE [tbl_Attendance_Event] (
[EventCode] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[File #] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Event Type] [numeric](9, 0) NULL ,
[EventDescription] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[Excused] [bit] NULL ,
[EventDate] [smalldatetime] NULL ,
[EventDuration] [money] NULL ,
[PointValue] [money] NULL ,
[ConsecDayCount] [numeric](9, 0) NULL ,
[Consecutive_Days] [bit] NULL ,
[EventRemove] [bit] NULL ,
[EventRemoveDate] [datetime] NULL ,
CONSTRAINT [PK_tbl_Attendance_Event] PRIMARY KEY NONCLUSTERED
(
[EventCode]
) WITH FILLFACTOR = 90 ON [PRIMARY] ,
CONSTRAINT [FK_tbl_Attendance_Event_tbl_Event_Types
] FOREIGN KEY
(
[Event Type]
) REFERENCES [tbl_Event_Types] (
[EventID]
)
) ON [PRIMARY]
GO
CREATE TABLE [tbl_Event_Types] (
[EventID] [numeric](9, 0) IDENTITY (1, 1) NOT NULL ,
[EventDescription] [varchar] (75) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[EventPoints] [smallmoney] NULL ,
[ExcepID] [numeric](9, 0) NULL ,
[TardyLogic] [bit] NULL ,
[Minimum Minutes] [numeric](9, 0) NULL ,
[Maximum Minutes] [numeric](9, 0) NULL ,
[ExtendsYearWindow] [bit] NULL CONSTRAINT
[DF_tbl_Event_Types_ExtendsYearWindow] DEFAULT (0),
[RuinsPerfectMonthlyAttendace] [bit] NOT NULL CONSTRAINT
[DF_tbl_Event_Types_RuinsPerfectMonthlyA
ttendace] DEFAULT (0),
[LogEvent] [bit] NULL ,
[PayCodeEvent] [bit] NULL ,
[Paycode] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Consecutive_Days] [bit] NULL ,
[AddToDropOffPeriod] [bit] NULL ,
CONSTRAINT [PK_tbl_Event_Types] PRIMARY KEY CLUSTERED
(
[EventID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
There are currently no rows that match the query, but I want to get
back a zero if that is the case. In other words, no rows = 0 for my
purposes. This query is in a stored procedure that returns the number
of points an employee has, so if there are no points I'd like a zero,
to do further processing with that zero. I could mess with the VB code
to make it zero there if there's no rows in the recordset, but this is
something that I've done with Oracle and is very useful in lots of
cases. I've Googled and seen responses that the
isnull(sum(isnull(expression, value)), value) should work, so I'm
missing something here!
Thanks
Pat|||If you want to see the groups where no matching rows exist by the where
clause, then you have to use [ALL] in the group by clause.
-- this is to reproduce what is happening to you
select c1, isnull(sum(1), 0)
from (select 1) as t1(c1)
where (c1 = 2)
group by c1
-- this is what you want
select c1, isnull(sum(1), 0)
from (select 1) as t1(c1)
where (c1 = 2)
group by all c1
go
AMB
"miapjp@.gmail.com" wrote:

> Hi,
> I'm having a heck of a time trying to get SQL Server 2000 to return a
> zero (0) if no rows are returned in a sum() statement. I know in
> Oracle you wrap an NVL around the whole shebang, and in Googling it
> seems as if SQL Server should work this way, too. But I cannot get it
> to work, I just keep getting null.
> I have tried:
> what I thought would work:
>
> SELECT ISNULL(SUM(ISNULL(PointValue, 0)), 0)
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> GROUP BY [File #]
> a case statement testing for null:
> SELECT CASE
> WHEN SUM(ISNULL(PointValue, 0)) IS NULL THEN 0
> ELSE SUM(ISNULL(PointValue, 0))
> END
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> GROUP BY [File #]
>
> wrapping the whole select statement in ISNULL as a subquery:
> SELECT ISNULL((SELECT SUM(ISNULL(PointValue, 0))
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()), 0)
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> and then to make sure what I was getting back was null and not empty
> ....something:
> declare
> @.n_sum numeric(6, 2)
> SELECT @.n_sum = ISNULL(SUM(ISNULL(PointValue, 0)), 0)
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> GROUP BY [File #]
> print 'sum is: ' + convert(char(8), isnull(@.n_sum, 0))
> sum is: 0.00
> What the heck am I doing wrong? I tried setting ANSI_NULL off and on,
> etc...but no go. I guess I could get around by using the variable and
> then returning that to the VB (since this is a stored proc used to find
> one value to return to the VB6 program), but that seems kind of messy.
> I would appreciate any help!
> TIA
> Pat
>|||You are dealing with two separate questions.
1. What is the sum on each row when there are records
2. What are the number of records (only important if 0)
One possible solution:
SELECT into a temp table. If the temp table has no rows, insert a row with
0. SELECT back off the temp table for your return value.
Since you have a filter on [File #], another option is to select into a
value and then test @.@.RowCount and set the value to 0 if @.@.RowCount = 0.
SOmething like:
DECLARE @.ReturnValue decimal
SELECT @.ReturnValue = ISNULL(SUM(ISNULL(PointValue, 0)), 0)
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '2/24/2005' AND getdate()
GROUP BY [File #]
IF (@.@.ROWCOUNT = 0)
SET @.ReturnValue = 0
SELECT @.ReturnValue
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"miapjp@.gmail.com" wrote:

> Hi,
> I'm having a heck of a time trying to get SQL Server 2000 to return a
> zero (0) if no rows are returned in a sum() statement. I know in
> Oracle you wrap an NVL around the whole shebang, and in Googling it
> seems as if SQL Server should work this way, too. But I cannot get it
> to work, I just keep getting null.
> I have tried:
> what I thought would work:
>
> SELECT ISNULL(SUM(ISNULL(PointValue, 0)), 0)
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> GROUP BY [File #]
> a case statement testing for null:
> SELECT CASE
> WHEN SUM(ISNULL(PointValue, 0)) IS NULL THEN 0
> ELSE SUM(ISNULL(PointValue, 0))
> END
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> GROUP BY [File #]
>
> wrapping the whole select statement in ISNULL as a subquery:
> SELECT ISNULL((SELECT SUM(ISNULL(PointValue, 0))
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()), 0)
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> and then to make sure what I was getting back was null and not empty
> ....something:
> declare
> @.n_sum numeric(6, 2)
> SELECT @.n_sum = ISNULL(SUM(ISNULL(PointValue, 0)), 0)
> FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
> tbl_event_types et ON ae.[event type] = et.eventID
> WHERE [File #] = '0001001047'
> AND EventDate BETWEEN '2/24/2005' AND getdate()
> GROUP BY [File #]
> print 'sum is: ' + convert(char(8), isnull(@.n_sum, 0))
> sum is: 0.00
> What the heck am I doing wrong? I tried setting ANSI_NULL off and on,
> etc...but no go. I guess I could get around by using the variable and
> then returning that to the VB (since this is a stored proc used to find
> one value to return to the VB6 program), but that seems kind of messy.
> I would appreciate any help!
> TIA
> Pat
>|||> There are currently no rows that match the query, but I want to get
> back a zero if that is the case.
Assuming that PointValue will always be positive if it *has* a value, you
can do this ugly stuff...
SELECT MAX(foo) FROM
(SELECT foo = COALESCE(SUM(PointValue),0)
FROM dbo.[tbl_Attendance_Event] ae INNER JOIN
tbl_event_types et ON ae.[event type] = et.eventID
WHERE [File #] = '0001001047'
AND EventDate BETWEEN '20050224' -- m/dd/yyyy is a terrible format
AND getdate()
UNION SELECT foo = 0) x|||>> ..get SQL Server 2000 to return a zero (0) if no rows are returned in a s
um() statement <<
SELECT COALESCE (SUM(i), 0) FROM EmptyTable;
However, what you are actually getting back is an empty set (ab nulo,
ex nulo) and the empty set is converted into a NULL. This is important
when you use EXISTS() predicates.|||>> There are currently no rows that match the query, but I want to get
back a zero if that is the case. In other words, no rows = 0 for my
purposes.
<<
then why don't you add a dummy row to every group:
select a, sum(b) from(
select a,b from some_table
union all
select distinct a, 0 from some_table) t|||Aha!
when I have the where clause limiting the sum, I don't need the group
by (right?). The original code also had the [file #] (again, not my
code, I don't make column names with spaces!!) in the select statement
even though it wasn't ever used - I don't know, I'm trying to make this
whole application work with bad code and bad underlying database
structure. In any case, I was trying to shoehorn in code to existing
code and not seeing the group by wasn't needed.
Thanks!!!!!

Saturday, February 25, 2012

Cant preview report

Hi ,
I have a long sql statement(a little bit complicated), but I've tried to
excute it in MS Sql server Management studio and it works correctly then I
put it in the dataset of Reporting services(MS Visual studio) , when I change
the panel to "Preview" ,MS visual studion seems no response and I have to
stop it through the system tool...
Please help! If you have the same experience.
Thanks in advance.
LanceI found a way to deal with this..might be not a best way.
Delete the DATESET and recreate a new one.
"Lance" wrote:
> Hi ,
> I have a long sql statement(a little bit complicated), but I've tried to
> excute it in MS Sql server Management studio and it works correctly then I
> put it in the dataset of Reporting services(MS Visual studio) , when I change
> the panel to "Preview" ,MS visual studion seems no response and I have to
> stop it through the system tool...
> Please help! If you have the same experience.
> Thanks in advance.
> Lance|||On Jan 31, 8:29 pm, Lance <La...@.discussions.microsoft.com> wrote:
> I found a way to deal with this..might be not a best way.
> Delete the DATESET and recreate a new one.
> "Lance" wrote:
> > Hi ,
> > I have a long sql statement(a little bit complicated), but I've tried to
> > excute it in MS Sql server Management studio and it works correctly then I
> > put it in the dataset of Reporting services(MS Visual studio) , when I change
> > the panel to "Preview" ,MS visual studion seems no response and I have to
> > stop it through the system tool...
> > Please help! If you have the same experience.
> > Thanks in advance.
> > Lance
Sounds like you might have performance issues with the report query.
You might try running the Database Engine Tuning Advisor against the
report query to improve the performance via suggested indexes. Also,
if you haven't already, you will want to convert the report query into
a stored procedure. This should improve your report performance as
well. Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant

Sunday, February 12, 2012

Can't get unicode strings using JDBC driver

Hi;

If I call the following to get a Statement, ResultSet.getString() works fine with unicode strings:
Statement stmt = conn.createStatement();

But If I use the following:
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

Then all chars > 127 are returned as an ? from ResultSet.getString().

I think this is a bug.

? - thanks - dave

ps - I believe it's the latest Sql Server 200 drivers - they are all dated 4/21/04|||David --

It looks like this was resolved in the microsoft.public.sqlserver.jdbcdriver forum. Let us know if you still have issues.

-shelby

Can't get unicode strings using JDBC driver

Hi;

If I call the following to get a Statement, ResultSet.getString() works fine with unicode strings:
Statement stmt = conn.createStatement();

But If I use the following:
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

Then all chars > 127 are returned as an ? from ResultSet.getString().

I think this is a bug.

? - thanks - dave

ps - I believe it's the latest Sql Server 200 drivers - they are all dated 4/21/04|||David --

It looks like this was resolved in the microsoft.public.sqlserver.jdbcdriver forum. Let us know if you still have issues.

-shelby

Can't get unicode strings

Hi;
If I call the following to get a Statement, ResultSet.getString()
works fine with unicode strings:
Statement stmt = conn.createStatement();
But If I use the following:
Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
Then all chars > 127 are returned as an ?
I think this is a (BIG BIG BIG) bug.
? - thanks - dave
david@.at-at-at@.windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
Page 2 Stage -- http://www.Page2Stage.com
Enemy Nations -- http://www.EnemyNations.com
me -- http://dave.thielen.com
Barbie Science Fair -- http://www.BarbieScienceFair.info
(yes I have lots of links)
What driver are you using? 2000, 2005 beta 1 or 2005 beta 2?
Thanks,
Angel Saenz-Badillos [MS] DataWorks
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging: http://weblogs.asp.net/angelsb/
"David Thielen" <david@.windward.net> wrote in message
news:3rqsk1tti6dmn9dr5ifevdsls612iqu7hs@.4ax.com...
> Hi;
> If I call the following to get a Statement, ResultSet.getString()
> works fine with unicode strings:
> Statement stmt = conn.createStatement();
> But If I use the following:
> Statement stmt =
> conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
> ResultSet.CONCUR_UPDATABLE);
> Then all chars > 127 are returned as an ?
> I think this is a (BIG BIG BIG) bug.
> ? - thanks - dave
> david@.at-at-at@.windward.dot.dot.net
> Windward Reports -- http://www.WindwardReports.com
> Page 2 Stage -- http://www.Page2Stage.com
> Enemy Nations -- http://www.EnemyNations.com
> me -- http://dave.thielen.com
> Barbie Science Fair -- http://www.BarbieScienceFair.info
> (yes I have lots of links)
|||I think the latest SqlServer 2000 ones. They are dated 4-21-04
thanks - dave
On Fri, 14 Oct 2005 15:13:15 -0700, "Angel Saenz-Badillos[MS]"
<angelsa@.online.microsoft.com> wrote:

>What driver are you using? 2000, 2005 beta 1 or 2005 beta 2?
>Thanks,
david@.at-at-at@.windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
Page 2 Stage -- http://www.Page2Stage.com
Enemy Nations -- http://www.EnemyNations.com
me -- http://dave.thielen.com
Barbie Science Fair -- http://www.BarbieScienceFair.info
(yes I have lots of links)
|||Dave:
That behavior doesn't reproduce for me -- can you post some code?
-shelby
"David Thielen" <david@.windward.net> wrote in message
news:teh0l19vvmg9gc2fvkes9a24rh9jpr9otv@.4ax.com...
>I think the latest SqlServer 2000 ones. They are dated 4-21-04
> thanks - dave
> On Fri, 14 Oct 2005 15:13:15 -0700, "Angel Saenz-Badillos[MS]"
> <angelsa@.online.microsoft.com> wrote:
>
> david@.at-at-at@.windward.dot.dot.net
> Windward Reports -- http://www.WindwardReports.com
> Page 2 Stage -- http://www.Page2Stage.com
> Enemy Nations -- http://www.EnemyNations.com
> me -- http://dave.thielen.com
> Barbie Science Fair -- http://www.BarbieScienceFair.info
> (yes I have lots of links)
|||On Mon, 17 Oct 2005 18:03:36 -0700, "Shelby Goerlitz [MSFT]"
<shelbyg@.online.microsoft.com> wrote:

>Dave:
>That behavior doesn't reproduce for me -- can you post some code?
Please take a look at http://www.windward.net/jdbc_unicode.zip Two key
notes:
1) use conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE) - if you just do conn.createStatement() it
works.
2) If you create a database with, for example Chinese as the default
charset, then Chinese can be retrieved - but not Russian. So the
"default" charset seems to be ok - but not other charsets. If your
default charset is English then most anything > 127 is a problem.
thanks - dave

>-shelby
>"David Thielen" <david@.windward.net> wrote in message
>news:teh0l19vvmg9gc2fvkes9a24rh9jpr9otv@.4ax.com.. .
>
david@.at-at-at@.windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
Page 2 Stage -- http://www.Page2Stage.com
Enemy Nations -- http://www.EnemyNations.com
me -- http://dave.thielen.com
Barbie Science Fair -- http://www.BarbieScienceFair.info
(yes I have lots of links)
|||Hi;
Any luck finding the bug using the example I created?
thanks - dave
On Tue, 18 Oct 2005 07:58:16 -0600, David Thielen <david@.windward.net>
wrote:

>On Mon, 17 Oct 2005 18:03:36 -0700, "Shelby Goerlitz [MSFT]"
><shelbyg@.online.microsoft.com> wrote:
>
>Please take a look at http://www.windward.net/jdbc_unicode.zip Two key
>notes:
>1) use conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
>ResultSet.CONCUR_UPDATABLE) - if you just do conn.createStatement() it
>works.
>2) If you create a database with, for example Chinese as the default
>charset, then Chinese can be retrieved - but not Russian. So the
>"default" charset seems to be ok - but not other charsets. If your
>default charset is English then most anything > 127 is a problem.
>thanks - dave
>
>
>david@.at-at-at@.windward.dot.dot.net
>Windward Reports -- http://www.WindwardReports.com
>Page 2 Stage -- http://www.Page2Stage.com
>Enemy Nations -- http://www.EnemyNations.com
>me -- http://dave.thielen.com
>Barbie Science Fair -- http://www.BarbieScienceFair.info
>(yes I have lots of links)
david@.at-at-at@.windward.dot.dot.net
Windward Reports -- http://www.WindwardReports.com
Page 2 Stage -- http://www.Page2Stage.com
Enemy Nations -- http://www.EnemyNations.com
me -- http://dave.thielen.com
Barbie Science Fair -- http://www.BarbieScienceFair.info
(yes I have lots of links)
|||Dave:
Sorry for the delay -- the issue has been escalated on this side and the dev
team is looking at it.
-shelby
"David Thielen" <david@.windward.net> wrote in message
news:cq5jl1d9gk6csfr197rc2lbaqfsk4lqgbs@.4ax.com...
> Hi;
> Any luck finding the bug using the example I created?
> thanks - dave
>
> On Tue, 18 Oct 2005 07:58:16 -0600, David Thielen <david@.windward.net>
> wrote:
>
> david@.at-at-at@.windward.dot.dot.net
> Windward Reports -- http://www.WindwardReports.com
> Page 2 Stage -- http://www.Page2Stage.com
> Enemy Nations -- http://www.EnemyNations.com
> me -- http://dave.thielen.com
> Barbie Science Fair -- http://www.BarbieScienceFair.info
> (yes I have lots of links)

Friday, February 10, 2012

can't get multiple values using reportItems

On a report I have I have a hidden table which I am trying to get values from for a total. On a seperate table, I have an if statement that checks if a product # matches one on this table. This works fine if there is only one record in the hidden table. If there are more than one records, the ReportItems call only see's the last textbox (the last record) of the hidden table. Here's the total expression I use

=IIf( sum(Fields!PickupDeliveryDetails_New.Value)+ sum(Fields!PickupDeliveryDetails_Extra.Value) <= 0, 0 ,((sum(Fields!PickupDeliveryDetails_New.Value) + sum(Fields!PickupDeliveryDetails_Extra.Value)) /

(ReportItems("textbox36").Value

)

)

* (Fields!Actuals_TotalPTypeCharge.Value)

+ (IIf(ReportItems("table6"."TableColumn1").Value = Fields!Product_BPCSNumber.Value, ReportItems("textbox50").Value ,

IIf(First(ReportItems("table6"."TableColumn1").Value) = Fields!Product_BPCSNumber.Value, First(ReportItems("textbox50").Value) , 0 ) ) )

)

Any help on this would be greatly appreciated.

Morgan

That piece of code was not working. Heres the working code.

=IIf( sum(Fields!PickupDeliveryDetails_New.Value)+ sum(Fields!PickupDeliveryDetails_Extra.Value) <= 0, 0 ,((sum(Fields!PickupDeliveryDetails_New.Value) + sum(Fields!PickupDeliveryDetails_Extra.Value)) /

(ReportItems("textbox36").Value

)

)

* (Fields!Actuals_TotalPTypeCharge.Value)

+ (IIf(ReportItems("textbox27").Value = Fields!Product_BPCSNumber.Value, ReportItems("textbox50").Value , 0 ) ))

|||First of all, never use neon green on the post its VERY HARD to read. Is it possible to do a group by Product# in the hidden table and then run an aggregate sum on the values you want added. That way when you reference the textbox in the hidden table from the other table it would be the sum of all values for that same product #|||

That wouldn't work because I need seperate values for each product type total. There is a group by product # but there are multiple product #s.

I have solved my problem by getting the results from the hidden table in the second table (i got the values in the dataset by using left outer joins).

I would still like to know if there is a way to do what I was trying to do if it ever came up again and it couldn't be solved in the query.