Use case for update the table value using sql query
Ex. table Gender_tbl and like this
id Gen_Name
1 Male
2 Male
3 Female
4 Femal
5 Male
no I have to update Gen_Name Male with M and Femal with F
solution:
UPDATE GENDER_TBL SET Gen_Name= (CASE WHEN (Gen_Name='Male') THEN 'M' WHEN (Gen_Name='Female') THEN 'F' else ' ' end)
Posted by Dilip Kumar
Sunday, January 11, 2009
Return Multiple Column vaue in Single column with comma separated using Sql
How can get multiple coumn value in single column with camman separeted using sql. like
I have table test2 and column name id and value like this
Id
1
2
3
4
5
6
..
and I want result like this 1,2,3,4,5,6,....
solution:
declare @a varchar(500)
set @a = ' '
select @a = @a + cast(id as varchar(20)) + ',' from test2
if len(@a)>1
set @a= left(@a,len(@a)-1)
select case @a when ' ' then '0' else @a end as id
I have table test2 and column name id and value like this
Id
1
2
3
4
5
6
..
and I want result like this 1,2,3,4,5,6,....
solution:
declare @a varchar(500)
set @a = ' '
select @a = @a + cast(id as varchar(20)) + ',' from test2
if len(@a)>1
set @a= left(@a,len(@a)-1)
select case @a when ' ' then '0' else @a end as id
Spacebar Check in TextBox Using Javascript
Trim Function using java script.Validation for text box if there only space using java script.validation for space in text box using java script.
Solution:
Create A textbox with id txtname and a button id btntest and wite this function inside script tag.
function trim(string)
{
var a = string.replace(/^\s+/, '');
return a.replace(/\s+$/, '')
}
function TestTrim()
{
x = window.document.getElementById("txtname");
str="Please Enter User Name";
if (trim(x.value)=="")
{
alert(str);
x.select();
x.focus();
return false ;
}
}
And then call the function on c#(code behind page)
btntest.Attributes.Add("onclick", "return TestTrim();");
Solution:
Create A textbox with id txtname and a button id btntest and wite this function inside script tag.
function trim(string)
{
var a = string.replace(/^\s+/, '');
return a.replace(/\s+$/, '')
}
function TestTrim()
{
x = window.document.getElementById("txtname");
str="Please Enter User Name";
if (trim(x.value)=="")
{
alert(str);
x.select();
x.focus();
return false ;
}
}
And then call the function on c#(code behind page)
btntest.Attributes.Add("onclick", "return TestTrim();");
Wednesday, January 7, 2009
How can search column in database using sql
How can search column in database using sql.
solution:-
use databasename
select it and execute and then write this query and execute it . it will give all the table in wich there will be the column name like you search.
select * from information_schema.columns where column_name like '%abc%'
solution:-
use databasename
select it and execute and then write this query and execute it . it will give all the table in wich there will be the column name like you search.
select * from information_schema.columns where column_name like '%abc%'
Search the table from database using sql
How can search the table name from the existing database if there are table exist but I forgot the full name of table in sql
Solution:- select * from information_schema.tables where table_name like '%abc%'
where abc is table name
Solution:- select * from information_schema.tables where table_name like '%abc%'
where abc is table name
Subscribe to:
Posts (Atom)