Sunday, February 12, 2012
Adding and populating a column to existing table
Basically 'column A' has numbers in it. I want SQL to look at 'column A' and if the first 5 digits of the number in 'column A' are 00001, then put 'description A' into new column 'column B'. If the first 5 digits of the number in 'column A' are 00002, then put 'description B' into 'column A' etc.
Any ideas?...If the first 5 digits of the number in 'column A' are 00002, then put 'description B' into 'column A' etc.
Are you sure, or you just made mistake and both descriptions should be in Column B? I assume so, otherwise you would rewrite your numbers in colA
create table t(colA varchar(30))
go
insert into t values('000012')
insert into t values('000023')
insert into t values('123445')
go
alter table t add colB varchar(30)
go
update t
set colB = case when colA like '00001%' then
'description A'
when colA like '00002%' then
'description B'
end
go
note: when you create your table and colA is integer you won't be able found out how many zeros are in the begining as zeros at the begining are ignored|||Thanks very much that's really helpful! :cool:
Adding an image
Hello, SuperNove289 (wow! :)
Simple question- simple answer:
Assume, you have this Table_1 with SelectedImages and Path fields.
CREATE TABLE [dbo].[Table_1](
[SelectedImages] [image] NOT NULL,
[Path] [ntext] NOT NULL
)
to add an image, do this:
INSERT INTO [testing].[dbo].[Table_1]
([SelectedImages]
,[Path])
VALUES
('D:\desktop\05022006\free_chart1.gif' ,'D:\desktop\05022006\free_chart1.gif' )
So, then you will do this :
SELECT [SelectedImages]
,[Path]
FROM [testing].[dbo].[Table_1]
You will get something like this:( <Binary data>)
SelectedImages Path
- -
0x443A5C6465736B746F705C30353032323030365C667265655F6368617274312E676966 D:\desktop\05022006\free_chart1.gif
(1 row(s) affected)
Probably the next question will be is how to see the entered image J
|||Hi SuperNova,
As suggested you may definately add images to your database but this is not the best practise you should avoid such BLOB operation refer http://research.microsoft.com/research/pubs/view.aspx?msr_tr_id=MSR-TR-2006-45 research done at MS, instead store file path of documents and handle it from Front End Applciation.
HTH
Hemantgiri S. Goswami
|||That depends on your coding language how to upload the data to the server, for C#, see this sample which is quite simple.http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=622943&SiteID=1
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de