Database

Quick Search

Return Multi Row value in a single column with comma seprated

February 27th, 2010 by admin
No comments »

Return Multi Row value in a single column with comma seprated using sql
I want Return output like 1,2,3,4,5 using sql.
There is one table in which has column
id name
1 Dilip
2 Dinesh
3 Varun
4 Dhanpat
5 Renuka

solution:
declare @a varchar(500)
set @a = ‘ ‘
select @a = @a + cast(id as varchar(20)) + ‘,’ from tablename
if … Read More

Check the column value if value is in string format with coma separated using Sql

February 27th, 2010 by admin
No comments »

If column value is in 1,2,34,23,44,444,12,23,… format than how can check the value using like operator in Sql. means if the coma separated value is in column in any table then how can check the value using like operator in Sql.

solution:
select * from s
where
sid like ’44,%’ or sid like ‘%,44,%’
or … Read More

Searching table from database using sql

February 27th, 2010 by admin
No comments »

This article demonstrate how to search a table in database using sql query :-

Solution:- select * from information_schema.tables where table_name like ‘%abc%’

where abc is table name

How to search column in database using sql

February 27th, 2010 by admin
No comments »

This article demonstrate how to search a table column in database using sql query :-

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 … Read More

Update Table value with case in Sql

February 27th, 2010 by admin
No comments »

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)