Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Friday, March 16, 2012

"SUM" of a varchar column?

I have a table that contains a number of columns containing either a varchar
value, or null. There are multiple rows per grouping. I would like to colapse
the multiple rows into a single row, either by appending the strings to each
other, or simply selecting the first (or last) one.
If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work, for
obvious reasons. I thought MAX would work, but MAX returns only one value for
all of the columns (as opposed to one per column) and the rest are left as
null.
Any suggestions?Here's an example...
The table contains this data, all items are varchar
3261 1317
3261 Non-Client
3261 2
3261 mmarkowitz
I'd like to turn this into...
3261 1317 Non-client 2 mmarkowitz|||This looks like a PIVOT. Can you flatten this table out on the client? If
not, see http://www.aspfaq.com/2462
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:7838E3D4-CD8D-46EB-A75F-D069B30EE9AB@.microsoft.com...
> I have a table that contains a number of columns containing either a
varchar
> value, or null. There are multiple rows per grouping. I would like to
colapse
> the multiple rows into a single row, either by appending the strings to
each
> other, or simply selecting the first (or last) one.
> If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work,
for
> obvious reasons. I thought MAX would work, but MAX returns only one value
for
> all of the columns (as opposed to one per column) and the rest are left as
> null.
> Any suggestions?|||"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:DD2FA7A5-A0F2-4BFF-85E9-42533F4E423C@.microsoft.com...
> Here's an example...
> The table contains this data, all items are varchar
>
> 3261 1317
> 3261 Non-Client
> 3261 2
> 3261 mmarkowitz
> I'd like to turn this into...
> 3261 1317 Non-client 2 mmarkowitz
I'm not sure if this will help, but you may want to take a look at the
GROUP BY WITH ROLLUP and WITH CUBE commands. It may work for what you are
after.
SELECT Col1, Max(Col2)
FROM tablename
GROUP BY Col1
WITH ROLLUP
HTH
Rick Sawtell
MCT, MCSD, MCDBA|||SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
FROM YourTable
GROUP BY col1
--
David Portas
SQL Server MVP
--|||I don't think this will work, he wants to flatten one ofthe two columns in
his table out into multiple columns...
--
http://www.aspfaq.com/
(Reverse address to reply.)
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1103306604.369012.58920@.z14g2000cwz.googlegroups.com...
> SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
> FROM YourTable
> GROUP BY col1
> --
> David Portas
> SQL Server MVP
> --
>|||OK. Looks to me like 5 columns but I guess that's just presentational ;-)
Tough to pivot without an explicit attribute for the column.
--
David Portas
SQL Server MVP
--|||"Aaron [SQL Server MVP]" wrote:
> This looks like a PIVOT.
Actually it is the RESULT of a pivot, which is why it is spread out
vertically like that.
But I did figure out a "trick". After reading the page you sent, I combined
their technique of ISNULL (instead of CASE) with MIN, and presto.
Thanks!
(anyone interested in the code?)

Sunday, March 11, 2012

"Sql" Is it possible!

What am I trying to do?

For each area (Area_No) by day (Date_Val) I want to establish if the Actual value (Act_Val) of sales for a given product (Prod_ID) is higher than the target value (Tgt_Val). This is signified by a 1 in TargetYes if it does or a 1 in TargetNo if it does not. There is an Inner Join (Ref_No) to ensure only specific areas are included. The result of this query gives me 1200 results with 20 different dates for each of the 60 Areas.
Qry_2 then adds up all the areas that do or do not achieve target for each date giving 20 results.
I have had to include various checks on Act_Val and Tgt_Val as there are multiple null or 0 value results that mess up my results.
This query works perfectly. My problem is that I have to combine these two queries into one. All my efforts have resulted in failure.
Please advise if there is either or..
1. A better way of achieving the same result in one query
2. A way to combine the queries

Qry_1
SELECT Table_A.Date_Val, IIf(Sum([Act_Val]) Is Null Or Sum([Tgt_Val]) Is Null Or Sum([Tgt_Val])=0 Or Sum([Tgt_Val])>Sum([Act_Val]),0,1) AS TargetYes, IIf(Sum([Act_Val]) Is Null Or Sum([Tgt_Val]) Is Null Or Sum([Tgt_Val])=0 Or Sum([Tgt_Val])>Sum([Act_Val]),1,0) AS TargetNo
FROM Table_A INNER JOIN Table_B ON Table_A.Ref_No = Table_B. Ref_No
WHERE (((Table_A.Prod_ID)>=20 And (Table_A.Prod_ID)<=26
GROUP BY Table_A.Date_Val, Table_B.Area_No
ORDER BY Table_B. Area_No;

Qry_2
SELECT qry_1.Date_Val, Sum(qry_1.TargetYes) AS SumOfTargetYes, Sum(qry_1.TargetNo) AS SumOfTargetNo
FROM qry_1
GROUP BY qry_1.Date_Val;

DATA TYPES!!
Date_Val = Date
Act_Val = Integer
Tgt_Val = Integer
Ref_No = Integer
Area_No = integer
Prod_ID = integer
Ref_No = integerTry this:
SELECT qry_1.Date_Val
, Sum(qry_1.TargetYes) AS SumOfTargetYes
, Sum(qry_1.TargetNo) AS SumOfTargetNo
FROM (
SELECT Table_A.Date_Val
, IIf(Sum([Act_Val]) Is Null
Or Sum([Tgt_Val]) Is Null
Or Sum([Tgt_Val])=0
Or Sum([Tgt_Val])>Sum([Act_Val]),0,1) AS TargetYes
, IIf(Sum([Act_Val]) Is Null
Or Sum([Tgt_Val]) Is Null
Or Sum([Tgt_Val])=0
Or Sum([Tgt_Val])>Sum([Act_Val]),1,0) AS TargetNo
FROM Table_A INNER JOIN Table_B
ON Table_A.Ref_No = Table_B.Ref_No
WHERE (((Table_A.Prod_ID)>=20 And (Table_A.Prod_ID)<=26
GROUP BY Table_A.Date_Val, Table_B.Area_No
ORDER BY Table_B. Area_No
) qry_1
GROUP BY qry_1.Date_Val;
;)|||Thanks. That worked a treat. I was struggling around how to pass the subquery values to the main query. None of the SQL books I have deal with this.

"Session" values

Is it possible to have the equivalent of a session value? What I'm wanting
to do is get the user to choose a value (item center) on the home page and
use that value to filter all the reports. Then if he wants to see the
reports for a different item center, he must go back to the home page and
choose a different one.
Even better, display the same list of item centers as a filter option at the
top of each report and default it to the currently chosen item center.
Any ideas on how to do this? I saw a post where someone asked if it was
possible to create a global variable to use throughout all reports and noone
answered him. So I'm assuming that it can't be done. But I'm asking anyhow.
Thanks
ToddTodd,
If you create your own web application, you can certainly keep track of some
value and pass it to your reports as one of the parameters. AFAIK, there is
no built-in functionality in the ReportServer or Report Manager web apps.
Ted
"Todd Bright" wrote:
> Is it possible to have the equivalent of a session value? What I'm wanting
> to do is get the user to choose a value (item center) on the home page and
> use that value to filter all the reports. Then if he wants to see the
> reports for a different item center, he must go back to the home page and
> choose a different one.
> Even better, display the same list of item centers as a filter option at the
> top of each report and default it to the currently chosen item center.
> Any ideas on how to do this? I saw a post where someone asked if it was
> possible to create a global variable to use throughout all reports and noone
> answered him. So I'm assuming that it can't be done. But I'm asking anyhow.
> Thanks
> Todd|||So basically each report is just a standalone report, right?
"Ted K" wrote:
> Todd,
> If you create your own web application, you can certainly keep track of some
> value and pass it to your reports as one of the parameters. AFAIK, there is
> no built-in functionality in the ReportServer or Report Manager web apps.
> Ted
> "Todd Bright" wrote:
> > Is it possible to have the equivalent of a session value? What I'm wanting
> > to do is get the user to choose a value (item center) on the home page and
> > use that value to filter all the reports. Then if he wants to see the
> > reports for a different item center, he must go back to the home page and
> > choose a different one.
> >
> > Even better, display the same list of item centers as a filter option at the
> > top of each report and default it to the currently chosen item center.
> >
> > Any ideas on how to do this? I saw a post where someone asked if it was
> > possible to create a global variable to use throughout all reports and noone
> > answered him. So I'm assuming that it can't be done. But I'm asking anyhow.
> >
> > Thanks
> > Todd

Thursday, March 8, 2012

"Resource is low, some results are dropped" using Timbuktu

You don't need to be familiar with Timbuktu to add value to this. If you
know SQL Server, have you ever had this happen?
I'm using Timbuktu 5.1 to remote into a SQL Server. I sometimes get this
exact message, verbatim, "Resource is low, some results are dropped."
I checked the server and it's got a load of resources. I never thought it
could be my client since I'm only asked Timbuktu to render the server
desktop. Any suggestions or common experience?
Larry wrote:
> You don't need to be familiar with Timbuktu to add value to this. If
> you know SQL Server, have you ever had this happen?
> I'm using Timbuktu 5.1 to remote into a SQL Server. I sometimes get
> this exact message, verbatim, "Resource is low, some results are
> dropped."
> I checked the server and it's got a load of resources. I never
> thought it could be my client since I'm only asked Timbuktu to render
> the server desktop. Any suggestions or common experience?
I'm not familiar with Timbuktu, but I've only ever seen that message in
Query Analyzer on a client when I run a batch that creates thousands of
result sets and use the grid display for the results.
David Gugick
Imceda Software
www.imceda.com
|||I've seen that message in Profiler before, when looking at really active
events without enough filters... Definitely a client issue, I believe.
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:OGkyz0u5EHA.3996@.TK2MSFTNGP10.phx.gbl...
> Larry wrote:
> I'm not familiar with Timbuktu, but I've only ever seen that message in
> Query Analyzer on a client when I run a batch that creates thousands of
> result sets and use the grid display for the results.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

"Resource is low, some results are dropped" using Timbuktu

You don't need to be familiar with Timbuktu to add value to this. If you
know SQL Server, have you ever had this happen?
I'm using Timbuktu 5.1 to remote into a SQL Server. I sometimes get this
exact message, verbatim, "Resource is low, some results are dropped."
I checked the server and it's got a load of resources. I never thought it
could be my client since I'm only asked Timbuktu to render the server
desktop. Any suggestions or common experience?Larry wrote:
> You don't need to be familiar with Timbuktu to add value to this. If
> you know SQL Server, have you ever had this happen?
> I'm using Timbuktu 5.1 to remote into a SQL Server. I sometimes get
> this exact message, verbatim, "Resource is low, some results are
> dropped."
> I checked the server and it's got a load of resources. I never
> thought it could be my client since I'm only asked Timbuktu to render
> the server desktop. Any suggestions or common experience?
I'm not familiar with Timbuktu, but I've only ever seen that message in
Query Analyzer on a client when I run a batch that creates thousands of
result sets and use the grid display for the results.
--
David Gugick
Imceda Software
www.imceda.com|||I've seen that message in Profiler before, when looking at really active
events without enough filters... Definitely a client issue, I believe.
--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:OGkyz0u5EHA.3996@.TK2MSFTNGP10.phx.gbl...
> Larry wrote:
> > You don't need to be familiar with Timbuktu to add value to this. If
> > you know SQL Server, have you ever had this happen?
> >
> > I'm using Timbuktu 5.1 to remote into a SQL Server. I sometimes get
> > this exact message, verbatim, "Resource is low, some results are
> > dropped."
> >
> > I checked the server and it's got a load of resources. I never
> > thought it could be my client since I'm only asked Timbuktu to render
> > the server desktop. Any suggestions or common experience?
> I'm not familiar with Timbuktu, but I've only ever seen that message in
> Query Analyzer on a client when I run a batch that creates thousands of
> result sets and use the grid display for the results.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

"replace value of" and enum

I've created XML SCHEMA COLLECTION AS
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Order" nillable="true" type="Order" />
<xs:complexType name="Order">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Status"
type="OrderStatus" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="OrderStatus">
<xs:restriction base="xs:string">
<xs:enumeration value="New" />
<xs:enumeration value="Pending" />
<xs:enumeration value="Complete" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
Now I'd like to update OrderStatus:
UPDATE Orders
SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with "Expired"')
I get:
Msg 2247, Level 16, State 1, Procedure Orders_Select
XQuery [dbo.Orders.OrderXml.modify()]: The value is of type "xs:string",
which is not a subtype of the expected type "OrderStatus".
The below does not work either:
UPDATE Orders
SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with
OrderStatus("Expired")')
How do I make this work?
ThanksNever mind, ("Expired" cast as OrderStatus) does the trick.
"Chris Carter" <anonymous@.discussions.microsoft.com> wrote in message
news:%23AHmjrHKGHA.2392@.TK2MSFTNGP09.phx.gbl...
> I've created XML SCHEMA COLLECTION AS
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema elementFormDefault="qualified"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="Order" nillable="true" type="Order" />
> <xs:complexType name="Order">
> <xs:sequence>
> <xs:element minOccurs="1" maxOccurs="1" name="Status"
> type="OrderStatus" />
> </xs:sequence>
> </xs:complexType>
> <xs:simpleType name="OrderStatus">
> <xs:restriction base="xs:string">
> <xs:enumeration value="New" />
> <xs:enumeration value="Pending" />
> <xs:enumeration value="Complete" />
> </xs:restriction>
> </xs:simpleType>
> </xs:schema>
>
> Now I'd like to update OrderStatus:
> UPDATE Orders
> SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with
> "Expired"')
> I get:
> Msg 2247, Level 16, State 1, Procedure Orders_Select
> XQuery [dbo.Orders.OrderXml.modify()]: The value is of type "xs:string",
> which is not a subtype of the expected type "OrderStatus".
> The below does not work either:
> UPDATE Orders
> SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with
> OrderStatus("Expired")')
>
> How do I make this work?
>
> Thanks
>
>
>

"replace value of" and enum

I've created XML SCHEMA COLLECTION AS
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Order" nillable="true" type="Order" />
<xs:complexType name="Order">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Status"
type="OrderStatus" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="OrderStatus">
<xs:restriction base="xs:string">
<xs:enumeration value="New" />
<xs:enumeration value="Pending" />
<xs:enumeration value="Complete" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
Now I'd like to update OrderStatus:
UPDATE Orders
SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with "Expired"')
I get:
Msg 2247, Level 16, State 1, Procedure Orders_Select
XQuery [dbo.Orders.OrderXml.modify()]: The value is of type "xs:string",
which is not a subtype of the expected type "OrderStatus".
The below does not work either:
UPDATE Orders
SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with
OrderStatus("Expired")')
How do I make this work?
Thanks
Never mind, ("Expired" cast as OrderStatus) does the trick.
"Chris Carter" <anonymous@.discussions.microsoft.com> wrote in message
news:%23AHmjrHKGHA.2392@.TK2MSFTNGP09.phx.gbl...
> I've created XML SCHEMA COLLECTION AS
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema elementFormDefault="qualified"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="Order" nillable="true" type="Order" />
> <xs:complexType name="Order">
> <xs:sequence>
> <xs:element minOccurs="1" maxOccurs="1" name="Status"
> type="OrderStatus" />
> </xs:sequence>
> </xs:complexType>
> <xs:simpleType name="OrderStatus">
> <xs:restriction base="xs:string">
> <xs:enumeration value="New" />
> <xs:enumeration value="Pending" />
> <xs:enumeration value="Complete" />
> </xs:restriction>
> </xs:simpleType>
> </xs:schema>
>
> Now I'd like to update OrderStatus:
> UPDATE Orders
> SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with
> "Expired"')
> I get:
> Msg 2247, Level 16, State 1, Procedure Orders_Select
> XQuery [dbo.Orders.OrderXml.modify()]: The value is of type "xs:string",
> which is not a subtype of the expected type "OrderStatus".
> The below does not work either:
> UPDATE Orders
> SET OrderXml.modify('replace value of (/Order[1]/Status[1]) with
> OrderStatus("Expired")')
>
> How do I make this work?
>
> Thanks
>
>
>

"Refresh" an SQLDataSource object programmatically

Background - I have a page that uses a numeric value stored in a Session object variable as the parameter for three different SQLDataSource objects, which provide data to two asp:Repeaters and an asp:DataList. Also, in the Page_Load, I use this value to to seed a stored procedure and an SQLDataReader to populate several unbound Labels. This works fine. In addition, I have a collection of 6 TextBoxes, an unbound Listbox, and two Buttons to allow the user to do searching and selection of potential matches. This basically identifies a new numeric value that I store in the Session variable and PostBack the page (via one of the buttons). This also works fine.

Problem - I have been tasked with taking a different page and adding six textboxes to collect the search values, but to post over to this page, populate the existing search-oriented TextBoxes, adn programmatically triggering the search. Furthermore, I have to detect the number of matching records and, if only 1, have the Repeaters and DataList display the results based on the newly selected record's key numeric value, as well as populating the unbound Labels. I have managed to get all of this accomplished except for programmatically triggering the Repeaters and DataList "refresh". These controls only populate as expected if a button is clicked a subsequent time, which makes sense, since that would trigger a PostBack and the Page_Load uses the new saved numeric key value from the Session.

My history in app development is largely from Windows Forms development (VB6), this is my second foray into Web Form dev with ASP.NET 2.0. I am willing to acceptthat what I am trying to do does not fit into the ASP environment, but I have to think that this is something that has been done before, and (hopefully) there is a way to do what I need.

Any ideas, oh great and wise Forum readers? *smile*

I don't think I have fully understood your problem. But when the user clicks search button you need to refresh the sqldatasource and call your_repeaters_or_datalist.DataBind() to refresh repeaters or datalist. If you have code in Post_Back you don't want to trigger you can include it in
if (!Page.IsPostBack)
{
////your code
}

|||

Thanks for the response. Hopefully this helps clarify my situation: The source page has several text boxes that mirror those on the target page. When a specific button on the source page is clicked, the contents of the source text boxes is written to the Session object and a redirect cross-posts to the target page. The Page_Load on the target page checks IsPostback and if it is a cross-page post, the code checks the origin of the action (via a Session variable), and updates the textboxes on the target page with the search parameters. In code, I poppulate a listbox (with results of a SQL stored procedure) with potential matches. If more than one match is returned, I want it to stop and await user interaction (And I have it at that point.) However, if only one match is returned, I have tried to save the key record value back to the Session object, so it can be available to the SQLDataSources that use it as its source value. This is not occurring.

IIn your response, you mentioned "you need to refresh the sqldatasource and call your_repeaters_or_datalist.DataBind() to refresh". That (refreshing the sqldatasource) is what I am trying to do. How can I get them to refresh without issuing an additional postback to the target page? Is there a method that I need to invoke on the sqldatasource objects to do that? It sounds like I am close, but not quite sure what to do at this point.

|||

Is there a method that I need to invoke on the sqldatasource objects to do that?

yes. Assume DataList control yourdatalist is bound to sqldatasource camDS,call following code to refresh:

camDS.SelectCommand ="searchcam";
camDS.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
camDS.SelectParameters.Add("keyword1","para1 ");
yourdatalist.DataBind();

How can I get them to refresh without issuing an additional postback to the target page?

I don't think this can be achieved without post back since data is saved at the server.

Saturday, February 25, 2012

"Multiple-Step operation cannot be generated Check each status value" Error

Hi All,

I have a field 'Rowguid' of type uniqueidentifier in a table. This field is the last field in the table. In this case if I update a record through the application I don't get any error. Suppose if there are additional fields after the field Rowguid I get the error "Multiple-Step operation cannot be generated Check each status value"

For your reference I have used the following statement to add the RowGuid field

Alter table <tablename>
Add RowGuid uniqueidentifier ROWGUIDCOL NOT NULL Default (newid())

Can anyone please help me.

Thanks

SatheshPost your update statement, and any trigger code on this table.|||Where's Brett when we need him?

Logically, columns don't have any order within a table. It so happens that the current implementation of Microsoft SQL Server has a physical order, but that's implementation dependant. Relying on a column order (logical or physical) is a bug waiting to happen!

The problem is that you are not specifying a column list for your INSERT statement, you are relying on an implied order. Once you add columns so that the rowid is no longer the last column, your assumed order bytes you. If you specify the columns via a column list, this won't be a problem.DROP TABLE BadExample
GO
CREATE TABLE BadExample (
comment NVARCHAR(25)
)
GO

INSERT INTO BadExample
SELECT 'Simple case'

SELECT * FROM BadExample
GO

ALTER TABLE BadExample
ADD RowGuid uniqueidentifier ROWGUIDCOL NOT NULL
DEFAULT (newid())

INSERT INTO BadExample (comment)
SELECT 'Not as simple example'

SELECT * FROM BadExample
GO

ALTER TABLE BadExample
ADD myDate DATETIME NOT NULL
DEFAULT GetDate()
GO

INSERT INTO BadExample (comment, myDate)
SELECT 'This works!', '1950-01-02'

SELECT * FROM BadExample
GO

INSERT INTO BadExample
SELECT 'This fails', '1960-03-04'

SELECT * FROM BadExample-PatP|||The problem is that you are not specifying a column list for your INSERT statement, you are relying on an implied order.How did you come up with that from his post!?

Sunday, February 19, 2012

"Invalid Character value for cast specification" from VC++ when i execute a proc

Hi Everybody,

I have a question regarding the running of a procedure from VC++ in SQL server.

well this is the scenario.

i have a procedure in SQL server and i am running that thru my VC++ code.
:eek:
i have a recordset class and i create an object of it and then do a obj.Open(). the procedure is fetching 24 records correctly in the query analyser and in my while(!(obj.IsEOF())) loop it gets the first record correctly but the moment it encounters obj.MoveNext(); it bombs and gives me the following error..

"Invalid Character value for cast specification ".

i don't know why this is happening

Thanks for you help.Somewhere in your Transact-SQL code you are trying to convert a character value to another datatype. My first guess would be DATETIME, next might be INT or another numeric datatype. This is usually either in a column you are returning or in a WHERE clause, but it can happen anywhere you can refer to a column.

-PatP|||BTW, since this actually appears to be a Transact-SQL problem, I'm moving the thread back to the Microsoft SQL forum.

-PatP

"insert into" with text type - newbie

Hello,

When I try "Insert Into" with a text column value that's very long, I
only get a cropped version inserted (I know because when I
programmatically access the field, it's cropped-- I'm not just
assuming this from query manager). The text column has a default size
of small, however I don't understand why it is only inserting the
default amoutn instead of the whole string. I am using "Insert Into
table (blah, blah) values (blah, 'loooooooooooooooooooooooooooong
entry')", and programmatically running that command.

I'm stumped. Why is it inserting only part of the long entry value?"vavavoomy2" <vavavoomy2@.yahoo.com> wrote in message
news:c5e42899.0310280942.177d251c@.posting.google.c om...
> Hello,
> When I try "Insert Into" with a text column value that's very long, I
> only get a cropped version inserted (I know because when I
> programmatically access the field, it's cropped-- I'm not just
> assuming this from query manager). The text column has a default size
> of small, however I don't understand why it is only inserting the
> default amoutn instead of the whole string. I am using "Insert Into
> table (blah, blah) values (blah, 'loooooooooooooooooooooooooooong
> entry')", and programmatically running that command.
> I'm stumped. Why is it inserting only part of the long entry value?

What does a "default size of small" mean? Text columns in MSSQL don't have a
variable width, are you talking about a char/varchar column?

In any case, you should probably check if you have ANSI_WARNINGS set OFF in
the connection properties for your client. By default this is on (for OLE
DB/ODBC at least), and inserting data which would be truncated gives an
error. Setting it to off suppresses the error and allows the insert to
happen.

If that isn't the case, can you post your CREATE TABLE statement, and an
INSERT statement which reproduces the problem? Also, does the error happen
when you execute the INSERT manually in Query Analyzer or only
programmatically?

Simon|||"vavavoomy2" <vavavoomy2@.yahoo.com> wrote in message
news:c5e42899.0310280942.177d251c@.posting.google.c om...
> Hello,
> When I try "Insert Into" with a text column value that's very long, I
> only get a cropped version inserted (I know because when I
> programmatically access the field, it's cropped-- I'm not just
> assuming this from query manager). The text column has a default size
> of small, however I don't understand why it is only inserting the
> default amoutn instead of the whole string. I am using "Insert Into
> table (blah, blah) values (blah, 'loooooooooooooooooooooooooooong
> entry')", and programmatically running that command.
> I'm stumped. Why is it inserting only part of the long entry value?

What does a "default size of small" mean? Text columns in MSSQL don't have a
variable width, are you talking about a char/varchar column?

In any case, you should probably check if you have ANSI_WARNINGS set OFF in
the connection properties for your client. By default this is on (for OLE
DB/ODBC at least), and inserting data which would be truncated gives an
error. Setting it to off suppresses the error and allows the insert to
happen.

If that isn't the case, can you post your CREATE TABLE statement, and an
INSERT statement which reproduces the problem? Also, does the error happen
when you execute the INSERT manually in Query Analyzer or only
programmatically?

Simon

"ImpersonateClient" property in Yukon

Hi,
Does anybody knows how to get the value for "ImpersonateClient" property
which is on IntegratedSecurity Object in SQL - DMO for SQL Server 2005
(Yukon).
Documentation says that the functionality has been moved to "Server
Connection" class of SMO but I couldnt find the property that will return
the result for the above.
TIA
PraThe documentation states that the ImpersonnateClient property is a Settings
class property but I don't see it implemented there. As a workaround,
another method to retrieve the value:
string proxyAccount = (string) ServerConn.ExecuteScalar(
"SELECT credential_identity" +
" FROM sys.credentials" +
" WHERE name = N'##xp_cmdshell_proxy_account##'");
I'm not sure if this a documentation or product issue. I submitted feedback
at http://lab.msdn.microsoft.com/productfeedback/.
Hope this helps.
Dan Guzman
SQL Server MVP
"Pra" <ekke_nikhil@.yahoo.co.uk> wrote in message
news:uTPjvE8KGHA.500@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Does anybody knows how to get the value for "ImpersonateClient"
> property which is on IntegratedSecurity Object in SQL - DMO for SQL Server
> 2005 (Yukon).
> Documentation says that the functionality has been moved to "Server
> Connection" class of SMO but I couldnt find the property that will return
> the result for the above.
>
> TIA
> Pra
>

"ImpersonateClient" property in Yukon

Hi,
Does anybody knows how to get the value for "ImpersonateClient" property
which is on IntegratedSecurity Object in SQL - DMO for SQL Server 2005
(Yukon).
Documentation says that the functionality has been moved to "Server
Connection" class of SMO but I couldnt find the property that will return
the result for the above.
TIA
Prasad
The documentation states that the ImpersonnateClient property is a Settings
class property but I don't see it implemented there. As a workaround,
another method to retrieve the value:
string proxyAccount = (string) ServerConn.ExecuteScalar(
"SELECT credential_identity" +
" FROM sys.credentials" +
" WHERE name = N'##xp_cmdshell_proxy_account##'");
I'm not sure if this a documentation or product issue. I submitted feedback
at http://lab.msdn.microsoft.com/productfeedback/.
Hope this helps.
Dan Guzman
SQL Server MVP
"Prasad" <ekke_nikhil@.yahoo.co.uk> wrote in message
news:uTPjvE8KGHA.500@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Does anybody knows how to get the value for "ImpersonateClient"
> property which is on IntegratedSecurity Object in SQL - DMO for SQL Server
> 2005 (Yukon).
> Documentation says that the functionality has been moved to "Server
> Connection" class of SMO but I couldnt find the property that will return
> the result for the above.
>
> TIA
> Prasad
>

"ImpersonateClient" property in Yukon

Hi,
Does anybody knows how to get the value for "ImpersonateClient" property
which is on IntegratedSecurity Object in SQL - DMO for SQL Server 2005
(Yukon).
Documentation says that the functionality has been moved to "Server
Connection" class of SMO but I couldnt find the property that will return
the result for the above.
TIA
Prasad
The documentation states that the ImpersonnateClient property is a Settings
class property but I don't see it implemented there. As a workaround,
another method to retrieve the value:
string proxyAccount = (string) ServerConn.ExecuteScalar(
"SELECT credential_identity" +
" FROM sys.credentials" +
" WHERE name = N'##xp_cmdshell_proxy_account##'");
I'm not sure if this a documentation or product issue. I submitted feedback
at http://lab.msdn.microsoft.com/productfeedback/.
Hope this helps.
Dan Guzman
SQL Server MVP
"Prasad" <ekke_nikhil@.yahoo.co.uk> wrote in message
news:uTPjvE8KGHA.500@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Does anybody knows how to get the value for "ImpersonateClient"
> property which is on IntegratedSecurity Object in SQL - DMO for SQL Server
> 2005 (Yukon).
> Documentation says that the functionality has been moved to "Server
> Connection" class of SMO but I couldnt find the property that will return
> the result for the above.
>
> TIA
> Prasad
>

"ImpersonateClient" property in Yukon

Hi,
Does anybody knows how to get the value for "ImpersonateClient" property
which is on IntegratedSecurity Object in SQL - DMO for SQL Server 2005
(Yukon).
Documentation says that the functionality has been moved to "Server
Connection" class of SMO but I couldnt find the property that will return
the result for the above.
TIA
PrasadThe documentation states that the ImpersonnateClient property is a Settings
class property but I don't see it implemented there. As a workaround,
another method to retrieve the value:
string proxyAccount = (string) ServerConn.ExecuteScalar(
"SELECT credential_identity" +
" FROM sys.credentials" +
" WHERE name = N'##xp_cmdshell_proxy_account##'");
I'm not sure if this a documentation or product issue. I submitted feedback
at http://lab.msdn.microsoft.com/productfeedback/.
Hope this helps.
Dan Guzman
SQL Server MVP
"Prasad" <ekke_nikhil@.yahoo.co.uk> wrote in message
news:uTPjvE8KGHA.500@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Does anybody knows how to get the value for "ImpersonateClient"
> property which is on IntegratedSecurity Object in SQL - DMO for SQL Server
> 2005 (Yukon).
> Documentation says that the functionality has been moved to "Server
> Connection" class of SMO but I couldnt find the property that will return
> the result for the above.
>
> TIA
> Prasad
>

"ImpersonateClient" property in Yukon

Hi,
Does anybody knows how to get the value for "ImpersonateClient" property
which is on IntegratedSecurity Object in SQL - DMO for SQL Server 2005
(Yukon).
Documentation says that the functionality has been moved to "Server
Connection" class of SMO but I couldnt find the property that will return
the result for the above.
TIA
Prasad
The documentation states that the ImpersonnateClient property is a Settings
class property but I don't see it implemented there. As a workaround,
another method to retrieve the value:
string proxyAccount = (string) ServerConn.ExecuteScalar(
"SELECT credential_identity" +
" FROM sys.credentials" +
" WHERE name = N'##xp_cmdshell_proxy_account##'");
I'm not sure if this a documentation or product issue. I submitted feedback
at http://lab.msdn.microsoft.com/productfeedback/.
Hope this helps.
Dan Guzman
SQL Server MVP
"Prasad" <ekke_nikhil@.yahoo.co.uk> wrote in message
news:uTPjvE8KGHA.500@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Does anybody knows how to get the value for "ImpersonateClient"
> property which is on IntegratedSecurity Object in SQL - DMO for SQL Server
> 2005 (Yukon).
> Documentation says that the functionality has been moved to "Server
> Connection" class of SMO but I couldnt find the property that will return
> the result for the above.
>
> TIA
> Prasad
>

"ImpersonateClient" property in Yukon

Hi,
Does anybody knows how to get the value for "ImpersonateClient" property
which is on IntegratedSecurity Object in SQL - DMO for SQL Server 2005
(Yukon).
Documentation says that the functionality has been moved to "Server
Connection" class of SMO but I couldnt find the property that will return
the result for the above.
TIA
PrasadThe documentation states that the ImpersonnateClient property is a Settings
class property but I don't see it implemented there. As a workaround,
another method to retrieve the value:
string proxyAccount = (string) ServerConn.ExecuteScalar(
"SELECT credential_identity" +
" FROM sys.credentials" +
" WHERE name = N'##xp_cmdshell_proxy_account##'");
I'm not sure if this a documentation or product issue. I submitted feedback
at http://lab.msdn.microsoft.com/productfeedback/.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Prasad" <ekke_nikhil@.yahoo.co.uk> wrote in message
news:uTPjvE8KGHA.500@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Does anybody knows how to get the value for "ImpersonateClient"
> property which is on IntegratedSecurity Object in SQL - DMO for SQL Server
> 2005 (Yukon).
> Documentation says that the functionality has been moved to "Server
> Connection" class of SMO but I couldnt find the property that will return
> the result for the above.
>
> TIA
> Prasad
>

Thursday, February 16, 2012

"Find In" Comma Separated Value

Hi,

****SQL Server related question.

I have a table in which one of the columns (col1) holds a string, like: 1,2,3,4,5,6,7,8,9,10

I am passing an int value (@.intValue) to the sproc.

What I want to be able to do is query the table like...


SELECT * FROM myTable where @.intValue ... is in col1

Any ideas?

Thanks a lot!!!!you can do something like

SELECT * FROM myTable WHERE col1 LIKE '%' + convert(varchar,@.intValue) + '%'

hth|||Thanks for the response ndinakar!

I tried your suggestion...

It does work...to a point. However... in my concatenated string, it is a possibility that I will have something that looks like this.

3,4,5,34,6,21

Then, when I query this table...say I am looking for '2' ...it returns the record with 21 in it.

Any other ideas about how I can go about this? I am thinking that I might have to break this concatenated value into separate columns.

Thanks for the reply. I greatly appreciate it!|||same approach, but you need to insure you have leading and trailing seperators

from this:
3,4,5,34,6,21

to this:
,3,4,5,34,6,21,

now you search for %,val,%

or in your example ,2, which wont match ,21,|||Thanks a lot! That works great...exactly what I was looking for.

Thursday, February 9, 2012

"box" appearing instead of <NULL>

We are seeing occasions where a column value that should be NULL, is
displaying a little "box". This "box" actually prints when the column is
sent to a report. When selecting data, if the "box" is present, it is not
included when looking for NULLs in the column. If the select statement says
NOT NULL, the "box" is selected.
Does anyone know what is causing this?
We are running SQL Server 2000 version 8.00.761
Thanks.This is a non-printing character of some sort, probably passed in when
translating an input string through a different program or library.
Assuming it's the first character, take the row in question, and do this:
SELECT [1st char] = ASCII(SUBSTRING(<column_name>, 1, 1))
FROM
<table_name>
WHERE <clause to identify that bad row>;
Now you will get an answer like 4 or 3 or 0... so now you can take that
<answer> and say
SELECT <column_name> = REPLACE(<column_name>, CHAR(<answer> ), '')
FROM <table_name>;
"Doug" <Doug@.discussions.microsoft.com> wrote in message
news:7B29C100-1844-471D-B093-30A1130AB8CE@.microsoft.com...
> We are seeing occasions where a column value that should be NULL, is
> displaying a little "box". This "box" actually prints when the column is
> sent to a report. When selecting data, if the "box" is present, it is not
> included when looking for NULLs in the column. If the select statement
> says
> NOT NULL, the "box" is selected.
> Does anyone know what is causing this?
> We are running SQL Server 2000 version 8.00.761
> Thanks.

"box" appearing instead of <NULL>

We are seeing occasions where a column value that should be NULL, is
displaying a little "box". This "box" actually prints when the column is
sent to a report. When selecting data, if the "box" is present, it is not
included when looking for NULLs in the column. If the select statement says
NOT NULL, the "box" is selected.
Does anyone know what is causing this?
We are running SQL Server 2000 version 8.00.761
Thanks.This is a non-printing character of some sort, probably passed in when
translating an input string through a different program or library.
Assuming it's the first character, take the row in question, and do this:
SELECT [1st char] = ASCII(SUBSTRING(<column_name>, 1, 1))
FROM
<table_name>
WHERE <clause to identify that bad row>;
Now you will get an answer like 4 or 3 or 0... so now you can take that
<answer> and say
SELECT <column_name> = REPLACE(<column_name>, CHAR(<answer>), '')
FROM <table_name>;
"Doug" <Doug@.discussions.microsoft.com> wrote in message
news:7B29C100-1844-471D-B093-30A1130AB8CE@.microsoft.com...
> We are seeing occasions where a column value that should be NULL, is
> displaying a little "box". This "box" actually prints when the column is
> sent to a report. When selecting data, if the "box" is present, it is not
> included when looking for NULLs in the column. If the select statement
> says
> NOT NULL, the "box" is selected.
> Does anyone know what is causing this?
> We are running SQL Server 2000 version 8.00.761
> Thanks.