|
Take the boys query and add a where clause that filters out existing records so you do not get duplicates. You need to identify the primary key (unique data) in both fields that can be used to apply the filter.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I write MSSQL queries to retrieve unicode data. It shows data in result Grid like boxes it cannot be readable format, What to do if unicode character should be displayed in readable format in MSSQL result grid....
************ S G KORE *******************
|
|
|
|
|
I think it has something to do with the characters sets installed under windows. I know we have chinese installed and the unicode display Ok but japanese is just boxes.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have a unique id column in a table with values -
12
32
45
345
3534
45456
etc.
Now i want to make all the values to be 7 digit by placing 0's in front of each id for example above ids will be
0000012
0000032
0000045
0000345
0003534
0045456
Now there are 1000's of values that i need to change - what would be the best possible way to write query for this.
Thanks
|
|
|
|
|
|
That would only work if they're string values, which they shouldn't be. You could left pad them when you display them.
|
|
|
|
|
yeh they are int values. Anyway to do it for int ?
thanks
|
|
|
|
|
AndyInUK wrote: yeh they are int values. Anyway to do it for int ?
Why would you want to? The following values are all the same:
1
01
001
0001
Generally, you'll apply padding purely for display/writing to file purposes, and this should be accomplished in the client code - not in the database.
|
|
|
|
|
yes they mean same but when we try to sort its meaning will change thats y for sorting we need this
|
|
|
|
|
Can you explain? Why do you need to have preceding zeroes in a number to sort?
Simply put, if it is an integer, then
1. you cannot do it
2. you do not need it
|
|
|
|
|
because without zeroes its not sorting in ascending
like i have data
1
2
3
10
11
21
31
without zeroes its sorting like this
1
11
21
31
2
3
|
|
|
|
|
Bullshit if these values are in integer column.
|
|
|
|
|
As Danish said, this is a text sort, you need to check your data type.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
eraser950 wrote: because without zeroes its not sorting in ascending
like i have data
1
2
3
10
11
21
31
without zeroes its sorting like this
1
11
21
31
2
3
That means they are stored as text, and not numbers. Sorting numeric data types gives you the values in the right order.
|
|
|
|
|
True enough. I assumed they were strings because the question doesn't really make sense if they are numeric.
|
|
|
|
|
I assume mysql has similar sorts of functions but I have not had the pleasure, but in T-SQL / SQL Server you could do:
select ID = right('0000000' + convert(varchar(20),ID),7) from MyTable -- ID can be int or varchar
or
select ID = right('0000000' + ID,7) from MyTable -- OK only when ID is varchar.
Likewise you could put this into an update statement if for example you are in the process of converting your ID column from type int to varchar/text etc.
|
|
|
|
|
Helllo
I have a problem while updating data in Sql table,
i have a table named City it contains CityID,CityName,CityShortName
i have created a stored procedure
PROCEDURE [dbo].[UpdateCity]
@CityID int,@CityName nvarchar(50),@CityShortName nvarchar(50)
AS
BEGIN
Declare @ReturnVal nvarchar(20)
SET NOCOUNT ON;
SET XACT_ABORT ON
Begin Try
IF EXISTS (SELECT CityName From City WHERE CityName =@CityName)
BEGIN
SET @ReturnVal ='Already Exists!'
--Return @ReturnVal
END
ELSE
BEGIN
Update City Set CityName=@CityName,CityShortName=@CityShortName
where CityID=@CityID
Set @ReturnVal ='Updated SuccessFully'
--Return @ReturnVal
End
end try
but when i m just editing Shortname its not updating , but its working perfect when i m editing either cityname or cityname and shortname,,
i know that i m doing mistake but where i can't found
second thng how can i show message updated successfully or already exist as i m using asp gridview
Please help me
Thanx
|
|
|
|
|
Here is the source of your problem:
eraser950 wrote: IF EXISTS (SELECT CityName From City WHERE CityName =@CityName)
BEGIN
SET @ReturnVal ='Already Exists!'
--Return @ReturnVal
END
When you do not change the city name, that if clause returns true, and hence you return 'Already Exists!'.
Try:
IF EXISTS (SELECT CityName From City WHERE CityName =@CityName AND CityID<>@CityID)
|
|
|
|
|
|
Thnx its working perfect kindly tell me is this good approach or theres any other method to do this?
second how can show message as i m usng sqldatasource(GridView) to update and delete
|
|
|
|
|
Hello,
FOr example i have the following table
class name
1 m
1 n
1 a
1 b
1 c
2 d
2 e
2 f
I need the following result:
class name
1 m,n,a,b,c
2 d,e,f
I mean grouping by class and all the names in one row
|
|
|
|
|
Use Cursor
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
modified on Monday, September 20, 2010 9:16 AM
|
|
|
|
|
michaelgr1 wrote: all the names in one row
Do you mean "in one field"?
If using Sql Server, you can write a custom aggregation function. There's an example somewhere on MSDN or the help.
It may not be the best solution to this problem, but it's good to know how to do it.
|
|
|
|
|
I need it in a field.
How can i do it? can you show me please?
BTW, I have only read only access to the DB
|
|
|
|
|
Use the pivot command. You can find more information here[^].
|
|
|
|