|
Hi,
I use lower() and upper() for my varchars in sql.
I want to lower the 1st string, exception for the 1st char (that i want to upper)
For the 2nd string i want to upper all chars.
Like this:
Helen HUNT
Peter DOUGLAS
How i do this?
nelsonpaixao@yahoo.com.br
|
|
|
|
|
here it is:
<br />
<br />
DECLARE @val AS VARCHAR(255)<br />
SET @val='name surname'<br />
<br />
SELECT UPPER(SUBSTRING(@val,1,1))+LOWER( SUBSTRING(@val,2,CHARINDEX(' ',@val)-1))+<br />
UPPER (SUBSTRING(@val, CHARINDEX(' ',@val)+1,LEN(@val)))
Result is:
Name SURNAME
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
Can a partition function reference a database Schema?
It doesn't seem logical to me, but...
“If we are all in agreement on the decision - then I propose we postpone further discussion of this matter until our next meeting to give ourselves time to develop disagreement and perhaps gain some understanding of what the decision is all about.”-Alfred P. Sloan
|
|
|
|
|
Could you specify a little bit more what you mean by referencing a schema?
Mika
|
|
|
|
|
Sorry for the delay in getting back. Thank you for asking, but I found the answer. For SQL 2005 the answer is no.
“If we are all in agreement on the decision - then I propose we postpone further discussion of this matter until our next meeting to give ourselves time to develop disagreement and perhaps gain some understanding of what the decision is all about.”-Alfred P. Sloan
|
|
|
|
|
I am not totally sure what the proper terminology for this structure is but the situation is:
I have three tables
Table One: Category
-------------------
CatID (int, index)
Category (varchar) Example Values(fruit, vegetable, mineral, language. etc)
Table Two: Objects
----------------------
ObjectID (int, index)
Parent_Category (int, Foreign Key to CatID)
ObjectName (varchar) example Values (Apples, Brocolli, Copper, etc)
table Three: Content
------------------------
ContentID (primary key)
CatID (FK to table Category)
ObjectID (Fk to table Objects)
...OtherContent...
I need to construct a select statement that produces something similar to the following format
Fruit Vegetable Mineral Language
-------------------------------------------------
Apple X
Bananna X
French X
Brocolli X
Cherry X
Cabbage X
Iron X
Idealy, I would like to have the ContentID of the correspondig record from the third table (Content) displayed in place of each "X".
The goal is to generate an HTML page with an HREF at each "X" that links to a page that retrieves the specific record from the Content table.
Any suggestions?
modified on Monday, August 18, 2008 2:05 PM
|
|
|
|
|
Why no have a category id in the object table with foreign key to category table? Seems like you have a cross ref table which is only needed in a one to many or many to many relationship. Can an object have 2 categories?
|
|
|
|
|
There is a foreign key in the Objects table to the Category Table.
The example here is a simplified version of a customer requirement. The real data is actually some obscure industrial materials, but the structure I need is what is illustrated.
The output will actually be a web page with intersecting points (represented by the 'X's) Each intersection of material and category would be unique. A "Content" Record will have only one "Category" and One "Object."
|
|
|
|
|
first take Category table in @table or in #table
bcoz no of colmns depends upon ur no of rows in category table.
then join it with content table - > object table
& use switch case for ur specified format.
|
|
|
|
|
Don't know if this is an option for you but one possibility (which could be easy) is to create a stored procedure in order to return correct result set. Stored procedure could return a table type or a cursor (depending on the needs). This way you would have the full power of T-SQL to use and it would be easier to break the logic in to pieces.
Another way (haven't tested it though) could be using pivoting and correlated subqueries.
Mika
|
|
|
|
|
look into Pivot queries (presuming SQL 2005)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
actually i know it is always better for good performance to specify the column name in sql query rather than issuing select * from table name.
please tell me in detail all the reason that why we should not issue select * from table name.
Thanks
tbhattacharjee
|
|
|
|
|
Common reason is for execution time.If our data base is large and number of records are more than it is better to specify the column name rather than * .
|
|
|
|
|
aside from the other response, if you have a database that gets updated or changed fairly often(like mine, always adding on new features), and their data is added to existing tables, depending on where the column is added, removed (old, unused, found a better way, etc..), or renamed(doesnt happen much) it could break your code, if you're expecting an int in col 3 and i add a column to the begining of the table it could change the datatype in column 3 and you're code then wouldnt read it correctly. however if you list out every column you want, in selects and inserts you wont have this problem unless a column is renamed(rare) or removed, and its easy enough to do a search through the code and a sql script file to find where its used if you're going to remove it.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Example from the work force:
We have a vendor supplied system that has too much data in it; we only want to keep 2 years worth of data online and archive anything over 2 years old.
The archiving system used a statement similiar to:
Insert into Archive_Table select * from Source_Table
An in-house system was created to copy the data from production to archive, however, over time, the columns in the vendor supplied system chnaged: more were added, order changed etc.
The archiving system failed because the destination table was not updated to match the source table and the insert statement was expected the SAME number of columns, order and type of columns in the destination table.
Hope that helps.
Tim
|
|
|
|
|
Because all that data has to come across the network to you, increasing network load needlessly.
On the other hand, if you really want all the columns, then using * is OK.
|
|
|
|
|
If you explicitly specify the columns in a SELECT statement, they are guaranteed to be returned in the order you specify. Consequently, you may safely identify the columns as theReader(0), theReader(1), etc. rather than having to have the system look up the column names on every theReader("customerName") access. If, for whatever reason, the expected columns don't exist, it's probably better to have the problem caught in the SELECT statement than to throw an exception when the non-existent data is accessed.
If your code is genuinely interested in getting all the columns that are or ever will be in the database, including any that may be added in future, then SELECT * is appropriate. This may be the case, for example, in a database viewer (though unless a naming convention is used to indicate fields that should be regarded as confidential, such an approach could be dangerous even there). If you're only interested in a few fields, even if the fields of interest are at present the only ones in the database, you should specify explicitly the fields of interest.
|
|
|
|
|
iam having a string like this 'hi this is "john" iam a 'good' boy' how to split this string so that the words should come as
hi
this
john
iam
a
good
boy
plz help in this regard.
|
|
|
|
|
Cross posting is considered rude...
In any case, what has this got to do with Oracle?
|
|
|
|
|
just hit the return key on the typewriter instead of space key.
|
|
|
|
|
Another option is to insert enough spaces if word wrapping is on...
|
|
|
|
|
Hi all,
I wrote a StoredProcedure which returns a dataset.
But when i drag that SP into .dbml file, the return type of SP is becomes int, not ISingleResultType<>. I dont know reason for this.
When i call that SP i got Error / Return vale 0
Plz Help me.
Here my SP:
ALTER PROCEDURE [dbo].[USP_GetAdNames](
@user varchar(50),
@specialization smallint = null,
@country smallint = null,
@state tinyint = null,
@city varchar(50)= null,
@from datetime = null,
@to datetime = null
)
AS
CREATE TABLE #TEMPADS
(
int_ID int,
str_Name varchar(50)
)
DECLARE @query nvarchar(1000)
BEGIN
SET @query = N'INSERT INTO #TEMPADS SELECT transAds.int_AdID,transAds.str_Name
FROM TRANS_ADS AS transAds
WHERE transAds.str_UserID = '''+@user+''''
if (@specialization != null OR @specialization != 0)
SET @query = @query + ' AND tansAds.smallint_Specialization = '+cast(@specialization as varchar(10))
if (@country != null OR @country != 0)
SET @query = @query + ' AND transAds.smallint_CountryCode = '+cast(@country as varchar(10))
if(@state != null OR @state != 0)
SET @query = @query + ' AND transAds.tinyint_FocusState = '+cast(@state as varchar(10))
if(Ltrim(Rtrim(@city)) != '' OR Ltrim(Rtrim(@city)) != null)
SET @query = @query + ' AND transAds.str_FocusCity = '''+@city +''''
if(@from IS NOT NULL)
SET @query = @query + ' AND transAds.dt_Modifiedon >='''+convert(varchar(25),@from,101)+''''
if(@to IS NOT NULL)
SET @query = @query + ' AND transAds.dt_Modifiedon <='''+convert(varchar(25),@to,101)+''''
print @query
EXECUTE sp_sqlexec @query
SELECT int_ID,str_Name FROM #TEMPADS
END
///// When i execute in SQl Management Studio iam getting records as dataset. But not in my program.
I am calling that sp like this:
var query = from temp in DataContext1.USP_GetAdNames("kvs",null,null,null,null,null,null) select temp;
.....................................................
I also tried creating a partial class in DataContextMapping.Designer.cs file but no use.
Please suggest me, what went wrong in my SP.
|
|
|
|
|
Try using table variables instead of temporary tables since the result set of a stored procedure with temporary tables can not be inferred.
Regards,
Syed Mehroz Alam
|
|
|
|
|
The database engine for SQL Server 2008 Express is downloadable from: http://www.microsoft.com/express/sql/download/[^]
Management Studio Basic and Advanced Services (Full-Text Search and Reporting Services) are not yet released, but based on blogs the target is at the end of August.
In order to install SQL Server 2008 Express, you need to install first:
- Microsoft .Net Framework 3.5 SP1
- Windows Installer 4.5
Standalone version of Books Online can be downloaded from Microsoft SQL Server 2008 Books Online[^]
[Edit]
Also tools and advanced services are now released for download
[/Edit]
modified on Saturday, August 23, 2008 1:51 AM
|
|
|
|
|